.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Issue on System.Diagnostics.Process output

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
I am getting the following error message System.InvalidOperationException: StandardOut has not been redirected or the process hasn't started yet. for the below code which has to displays the Output of the command prompt command: Process p = new Process(); string result = ""; p.StartInfo.WorkingDirectory = "C:\\WINDOWS\\system32"; p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.Arguments = "/C ipconfig"; StreamReader stdOut = p.StandardOutput; p.WaitForExit(); p.Start(); result = stdOut.ReadToEnd(); if (!p.HasExited) { p.Kill(); } stdOut.Close(); p.Close(); Response.Write(result); System.Threading.Thread.Sleep(5000); Please help guys. Is I am doing correct. 

View Complete Post

More Related Resource Links

System.Diagnostics.Process.Start not work with IIS, but on ASP.NET Development Server

System.Diagnostics.Process.Start not work with IIS, but on ASP.NET Development Server 

Process (System.Diagnostics.Process) invoked by aspx hangs on iis6 / win2003

Hello all, I've encountered a problem trying to run an external exe from an aspx page. My code works fine when running under visual studio and also when running under iis7 on windows server 2008 SP1. It does not work on iis6 on windows 2003 sp2: 1. The executable is loaded and uses 560k or so of memory 2. The executable does not use any cpu 3. The executable does not appear to enter Main()  4. The invoking code hangs at WaitForExit() I've tried using different executables including a dummy that simply returned and that did not make any difference. I'm pretty sure that the credentials being used for the executable are correct because if I fudge the password, the process reports a login failure. I'm pretty sure that output blocking to the standard out and standard error streams is not the issue as a) it works on iis7 and b) when I first suspected this as the cause, I re-wrote the aspx to launch threads to read the streams. I've tried invoking my exe directly and via cmd.exe and that makes no difference. Anyway, if anyone has any ideas on this, it would be greatly appreciated. I've included a snippet of my code below. Thanks in advance... ...Beau                     // Create a new process to invoke the console app                     usi

System.Diagnostics.Process and Acrobat Reader

If I already have any PDF file being displayed in Adobe Reader, making the call System.Diagnostics.Process proc = Launch(sUniqueName, sPath, true, m_iWaitNone), then immediately examining proc.HasExited would indicate true, although the "sUniqueName" PDF would still be open.  This can't be correct!?

If I don't have any PDF files open before making the call, "sUniqueName" would be open, and examining proc.HasExited would indicate false... which is correct.  This is very repeatable.  Why would proc.HasExited = true when the PDF is still being displayed just because another PDF was opened prior to the call?

Thanks for any insight... this is driving me crazy!   :-P



Code follows:

      #region Launch()
        public System.Diagnostics.Process Launch(string sFilename, string sArgs, bool bCreateWindow, int iWaitMode)
            const int ERROR_FILE_NOT_FOUND = 2;
            const int ERROR_ACCESS_DENIED = 5;

            System.Diagnostics.Process proc =

Performance Tests: Precise Run Time Measurements with System.Diagnostics.Stopwatch

Everybody who does performance optimization stumbles sooner or later over the Stopwatch class in the System.Diagnostics namespace. And everybody has noticed that the measurements of the same function on the same computer can differ 25% -30% in run time. This article shows how single threaded test programs must be designed to get an accuracy of 0.1% - 0.2% out of the Stopwatch class. With this accuracy, algorithms can be tested and compared.

Team System: Streamline Team Projects With Process Templates


See how you can streamline your team projects using Process Templates in Visual Studio Team System (VSTS)

Brian A. Randell

MSDN Magazine December 2008

Advanced Basics: Monitor Your Apps with System.Diagnostics


It never fails. The application you just deployed ran great on your development machine-but stumbles in production. The problem might show up right away or maybe it creeps up over time. Now what?

Brad McCabe

MSDN Magazine July 2006

CLR Inside Out: Extending System.Diagnostics


The System. Diagnostics namespace in the Microsoft® . NET Framework contains powerful tracing capabilities. This includes the main tracing API: TraceSource. As you will see, the tracing APIs in System.

Krzysztof Cwalina

MSDN Magazine April 2006

Around the Horn: Engineer a Distributed System Using .NET Remoting for Process Intensive Analysis


Before the Microsoft .NET Framework, creating a distributed cluster of computers to perform scientific analysis was expensive in terms of hardware, programming and debugging time, and maintenance. You had to purchase expensive servers, spend time debugging network communication, design a distributed system completely different from a system deployed locally, and maintain a melting pot of error handling, data acquisition, networking, and analysis code. In this article, the author shows you how he was able to engineer a distributed computing system in C# to perform analysis of real-world data continuously acquired at high sampling rates, thanks to the .NET Framework.

Nate D'Anna

MSDN Magazine May 2005

system.net.mail cc issue


I have an array of addresses.....

	Protected Function GetData() As String()
Dim stringArr(3) As String

stringArr(0) = "youremail1@fakeaddress.com"
stringArr(1) = "youremail2@fakeaddress.com"
stringArr(2) = "youremail3@fakeaddress.com"

Return stringArr

End Function

I am getting an error when i run the code in the CC part....please put this in the right syntax..

MassMail.CC.Add() .......getdata???

merge replication system tables fragmentation issue

I have Merge replication going on in my environment. The problem is that system tables like MSmerge_content, MS merge _tombstone and MSmerge_genhistory are getting fragmented. We are rebuilding indexes time to time daily. But we want some good fix. Just send some good idea guys?

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Object canno

hello,i am using a web servicewrtitten in .net and i access the webservice from my wepApplication i get this error System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Object cannot be cast from DBNull to other types.my code is access webservice: protected void btnSave_Click(object sender, EventArgs e)        {            int intStatusCode;            dtProjectStatus = (DataTable)ViewState["dtProjectStatus"];            try            {                objService.Credentials = System.Net.CredentialCache.DefaultCredentials;                if(dtProjectStatus.Rows.Count>0)                {                  intStatusCode = objService.InsertTest(dtProjectStatus);                }   

How to SDelete from a System.Diagnostic.Process with no warning prompt

I have a need to securely delete files once my process is finished with them.  I have to write a file to disk, so another process can read it and process it.  It is not an option to simply write it to a stream because I have no control over the consumer of the file. So, I found the SDelete tool Sysinternals which should solve my problem nicely.  I wrappered that with the following static method in my Utility library: public static void SecureDelete(string fullyQualifiedFileName, string domain, string user, SecureString pswd) { // // This does not appear to be working properly... // it works under the debugger, but not when running as a service // using (System.Diagnostics.Process p = new System.Diagnostics.Process()) { p.StartInfo.FileName = "sdelete"; p.StartInfo.Arguments = string.Format("-q {0}", fullyQualifiedFileName); p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.StartInfo.RedirectStandardOutput = false; p.StartInfo.UseShellExecute = false; p.StartInfo.Domain = domain; p.StartInfo.UserName = user; p.StartInfo.Password = pswd; p.Start(); } } The problem is that when I run under the debugger (using my credentials) it works fine, but this code is called from a service which runs under the Network Service account, so

sql output is system.data.common

I have a query where I want to return the names of last 3 months in my table (stored as 'month year' e.g 'July 2010', 'August 2010') and bind them to a dropdown list. They bind as System.Data.Common?using (SqlCommand sqlCommand = conn.CreateCommand())            {                string dbQuery = "SELECT distinct [Time] from edata where [Time] >= DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP) - 3, 0) AND [Time] <  DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), 0);";                sqlCommand.CommandText = dbQuery;                sqlCommand.CommandType = CommandType.Text;                conn.Open();                using (SqlDataReader commandReader = sqlCommand.ExecuteReader())                {                   DropDownList_Time.DataSourc

Exception in System.Diagnostics.EventLog.get_EntryCount()

Hello,I am having an really weird exception which seems to originate in the BCL since the call stack does not show any of my code.Application is an event log processing service which uses the EntryWritten event of the System.Diagnostics.Eventlog class.The exceptions call stack is as follows:[System]System.ComponentModel.Win32ExceptionInterface unknownat System.Diagnostics.EventLogget_EntryCount()at System.Diagnostics.EventLogCompletionCallback(Object context)at System.Diagnostics.EventLogStaticCompletionCallback(Object context, Boolean wasSignaled)at System.Threading._ThreadPoolWaitOrTimerCallbackWaitOrTimerCallback_Context(Object state, Boolean timedOut)at System.Threading._ThreadPoolWaitOrTimerCallbackWaitOrTimerCallback_Context_f(Object state)at System.Threading.ExecutionContextRun(ExecutionContext executionContext, ContextCallback callback, Object state)at System.Threading._ThreadPoolWaitOrTimerCallbackPerformWaitOrTimerCallback(Object state, Boolean timedOut)Thats it. No sign of my own code. Yet, this happens like once or twice a day only, and ONLY on a Windows Vista SP1 installation. Anybody has any ideas whats that where it comes from, etc?CheersAndreas

System.Diagnostics not working in IIS 6: Urgent

Hi All, I have developed a ASP.NET C# web page which connects to remote conmputer command prompt using PSEXEC.exe and executes some command where the output of the command will get copied to the page. It works fine in the VS 2005 IDE. If the page is accessed via IIS from IE, the task PSEXEC.EXE appears in task manager of the server with the system account privilege after the method is triggered but nothing happens. Please find my present settings in IIS and others: 1. APP Pool Identity to Local System (Predefined) and also to a configurable admin account. 2. <processModel userName="SYSTEM" password="AutoGenerate" /> in Machine.Config file Also I've tried impersonasation in web.config file to an admin account. I am not able to sort this problem, please help. I've tried a lot spending more time. Code Is:Process p = new Process(); string result = ""; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = @"C:\psexec.exe"; p.StartInfo.Arguments = @"\\nawrkxp613 -u domain\usename -p Password1 cmd.exe /c ipconfig"; p.Start(); StreamReader stdOut = p.StandardOutput; p.WaitForExit(); result = stdOut.R

FCB::Open: Operating system error 32(The process cannot access the file because it is being used by

Hello all,I am running into an interesting scenario on my desktop.  I'm running developer edition on Windows XP Professional (9.00.3042.00 SP2 Developer Edition).  OS is autopatched via corporate policy and I saw some patches go in last week.  This machine is also a hand-me-down so I don't have a clean install of the databases on the machine but I am local admin.So, starting last week after a forced remote reboot (also a policy) I noticed a few of the databases didn't start back up.  I chalked it up to the hard shutdown and went along my merry way.  Friday however I know I shut my machine down nicely and this morning when I booted up, I was in the same state I was last Wenesday.  7 of the 18 databases on my machine came up withFCB:pen: Operating system error 32(The process cannot access the file because it is being used by another process.) occurred while creating or opening file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf'. Diagnose and correct the operating system error, and retry the operation.and it also logs  FCB:pen failed: Could not open file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf for file number 1. OS error: 32(The process cannot access the file because it is being used by another process.).I've caught references to the auto close feature being a possible culprit, no dice as the databases in question are set to Fal

The process could not be created for step 1 of job .....(reason: The system cannot find the file spe


Hi ,

I was trying your options by using "(operating system) cmdExec" to delete folders which were 15 days olders.  But here i am getting error if i look into view history of sql agent job... below is my command that i gave in Job step.

EXEC xp_cmdshell 'forfiles /p "z:\backup" -d 15 /c "cmd /c if @isDir==True echo RD /Q /S @FILE&RD /Q /S @FILE"'

And the error is :

The process could not be created for step 1 of job .....(reason: The system cannot find the file specified).  The Step failed.

but if i give this command in New Query Window, i am able to delete the folders successfully.

Please advice me if am wrong

R Anand

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend