System.Diagnostics.Process in ASP.NET

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top