System.Diagnostics.Process in ASP.NET

  • Thread starter Thread starter Wojtek
  • Start date Start date
W

Wojtek

Hi,

I am having problems to fetch the output of a command line program from
an ASP.NET application. My code works fine in a regular Forms or command
line application, but when running the same code in ASP.NET it hangs
indefinitely. I can see in the Task Manager that the command line
started, but when going through it with the debugger it seems to hang
when calling the WaitForExit() method on the Process instance.

I can start any other program without any problem when avoiding the
WaitForExit() call. But without that call I can't fetch the output...

Here's the sample code:

ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = "list http://testserver/svn/TestRepos";
psi.FileName = "svn.exe";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;

Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit(); // <-- *** it hangs here ***
string output = p.StandardOutput.ReadToEnd();


Any ideas?

Thanks in advance,
Wojtek
 
Doing WaitForExit before doing ReadToEnd can result in a deadlock, because
the process will block when its output stream buffer is full. Thus it can't
complete and your exit doesn't happen, because you r have to read the stream
to clear it so the process can exit.

This is actually covered in MSDN articles and examples on doing this.
 
Back
Top