Home All Groups Group Topic Archive Search About

System.Diagnostic.Process

Author
19 Jul 2006 11:11 PM
Guest
Does anyone know the best way to interact with a command application using
System.Diagnostic.Process if the command application never exits?

In other words, The OnOutputRecieved event doesn't fire until the app
exists, which is not too helpful because I want to interact with the app
while it's running.

Here's my code:

            // Set UseShellExecute to false for redirection
            _proc.StartInfo.UseShellExecute = false;
            _proc.EnableRaisingEvents = true;

            // Redirect the standard output of the command. 
            // This stream is read asynchronously using an event handler.
            _proc.StartInfo.RedirectStandardOutput = true;

            _proc.StartInfo.RedirectStandardError = redirectStandardError;

            // Redirect standard input as well.  This stream
            // is used synchronously.
            _proc.StartInfo.RedirectStandardInput = true;

            _proc.StartInfo.CreateNoWindow = true;
            _proc.StartInfo.WorkingDirectory = somePathISpecified;
            _proc.StartInfo.FileName = commandPath;
            _proc.StartInfo.Arguments = arguments;
            _proc.Start();

            // Start the asynchronous read of the output stream.
            _proc.BeginOutputReadLine();

Now, this works fine if it's not a blocking process, but reading output, and
passing input doesn't seem to work if the process doesn't exit.

Thanks for any help

Author
19 Jul 2006 11:23 PM
Guest
I found this article that looks like it'll be a big help if anyone else runs
into this:

http://www.codeproject.com/csharp/LaunchProcess.asp

Show quote
"Guest" wrote:

> Does anyone know the best way to interact with a command application using
> System.Diagnostic.Process if the command application never exits?
>
> In other words, The OnOutputRecieved event doesn't fire until the app
> exists, which is not too helpful because I want to interact with the app
> while it's running.
>
> Here's my code:
>
>             // Set UseShellExecute to false for redirection
>             _proc.StartInfo.UseShellExecute = false;
>             _proc.EnableRaisingEvents = true;
>
>             // Redirect the standard output of the command. 
>             // This stream is read asynchronously using an event handler.
>             _proc.StartInfo.RedirectStandardOutput = true;
>
>             _proc.StartInfo.RedirectStandardError = redirectStandardError;
>
>             // Redirect standard input as well.  This stream
>             // is used synchronously.
>             _proc.StartInfo.RedirectStandardInput = true;
>
>             _proc.StartInfo.CreateNoWindow = true;
>             _proc.StartInfo.WorkingDirectory = somePathISpecified;
>             _proc.StartInfo.FileName = commandPath;
>             _proc.StartInfo.Arguments = arguments;
>             _proc.Start();
>
>             // Start the asynchronous read of the output stream.
>             _proc.BeginOutputReadLine();
>
> Now, this works fine if it's not a blocking process, but reading output, and
> passing input doesn't seem to work if the process doesn't exit.
>
> Thanks for any help

AddThis Social Bookmark Button