473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

System.Diagnostics.Process in ASP.NET

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
Nov 19 '05 #1
1 2745
Oz
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.
"Wojtek" wrote:
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: marccruz | last post by:
Given an instance of System.Diagnostics.Process, how can I get the parent process o Given an instance of System.Diagnostics.Process, how can I get the child processes For example, I start a...
1
by: Heiko Besemann | last post by:
Dear group, I created an aspx page using System.Diagnostics.Process() to launch "tracert" from shell and redirect output to Response.Output which prints it as text/plain into my browsers window....
1
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I...
2
by: andreas | last post by:
hi, In windows xp in the start launch menu when i put notepad "c:\test.txt" i get notepad with test.txt in it. in vb.net when i state system.diagnostics.process.start("notepad.exe" i get...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
0
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine....
0
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to...
0
by: Colin Williams | last post by:
I am using the code below to map network drive and then fire up an app in a sub dir of that drive. However when using the file open dialog from that app, drive K: appears just as Network drive K:...
0
by: =?Utf-8?B?UHVjY2E=?= | last post by:
-- Hi I'm using vs2005, .net 2 for windows application. The application I started using System.Diagnostics.Process is having a "listFiles.StandardOutput" buffer size problem. I was wondering...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.