System.Diagnostics.Process in ASP.NET

Discussion in 'ASP .Net' started by Wojtek, May 20, 2005.

  1. Wojtek

    Wojtek Guest

    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
     
    Wojtek, May 20, 2005
    #1
    1. Advertising

  2. 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
    >
     
    =?Utf-8?B?T3o=?=, Aug 13, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simple Simon
    Replies:
    0
    Views:
    380
    Simple Simon
    Dec 15, 2003
  2. Ron Fidel
    Replies:
    4
    Views:
    4,158
    Ronen Fidel
    Jan 15, 2004
  3. Michael Johnson Sr.

    System.Diagnostics, Process and Security

    Michael Johnson Sr., Feb 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,864
    Michael Johnson Sr.
    Feb 13, 2004
  4. =?Utf-8?B?ZGFubEBkcmF3bmV0X25vX3NwYW0uY29t?=

    .bat from asp.net w/System.Diagnostics.Process?

    =?Utf-8?B?ZGFubEBkcmF3bmV0X25vX3NwYW0uY29t?=, Apr 10, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    3,693
    Alvin Bruney [MVP]
    Apr 12, 2004
  5. Ram
    Replies:
    2
    Views:
    6,159
Loading...

Share This Page