[Mono-devel-list] System.Diagnostics.Process redirection
Colin JN Breame
colin at breame.net
Sun Jul 3 18:47:03 EDT 2005
On Sunday 03 Jul 2005 16:45, John Bailo wrote:
>
> 1. Have you tried adding a catch so you can see any errors that might be
> thrown? You have that code nested in a try -- but no cache.
Yes I have - I've tried both a catch and a finally block around the suspect
line. It really is exiting at that point.
>
> 2. Have you stepped it through monodevelop?
I don't have monodevelop installed. I would be grateful if someone else could
try the program to see if they get the same result.
>
> 3. I know from Windows .NET that the methods for monitoring the state, and
> completion of a Process is somewhat ill-defined. Yes, there are several
> sample code examples but some say different things. For a project I did
> that send an lpr command, I ended up doing two things.
>
> Set a new Process equal to the actual process and monitor that as a kind of
> "handle". Two, put in a Thread.Sleep to give process a chance to "clean
> up". There seems to be some long disconnect between when the process
> 'stops' and when it 'really stops'.
>
> At least that has been my experience w/Windows.NET
>
> > .
> >
> > Any ideas what might be going on here? Could this be SIGPIPE related?
> >
> > -- Colin
> >
> > ps. mono 1.1.8.1
> >
> >
> >
> > using System;
> > using System.IO;
> > using System.Diagnostics;
> >
> > public class main_t {
> >
> > public static void Main() {
> > while (true) {
> > run();
> > }
> > }
> >
> > public static void run() {
> > Process p = null;
> >
> > try {
> > p = new Process();
> >
> > string pipe = "echo hello";
> >
> > int i = pipe.IndexOf(' ');
> > if (i == -1) {
> > p.StartInfo.FileName = pipe;
> > } else {
> > p.StartInfo.FileName = pipe.Substring(0,
> > i); p.StartInfo.Arguments = pipe.Substring(i+1, pipe.Length-i-1);
> > }
> >
> > p.StartInfo.UseShellExecute = false;
> > p.StartInfo.RedirectStandardInput = true;
> > try {
> > p.Start();
> > } catch (Exception e) {
> > Console.Error.WriteLine("could not
> > execute: {0}", pipe);
> > goto init_error;
> > }
> >
> > TextWriter stdout = Console.Out;
> > Console.SetOut(p.StandardInput);
> > stdout.WriteLine("1");
> > p.StandardInput.WriteLine("hello world!");
> > stdout.WriteLine("2");
> > Console.SetOut(stdout);
> >
> > p.StandardInput.Close();
> >
> > if (p != null) {
> > p.WaitForExit();
> > }
> >
> > } finally {
> > if (p != null) p.Close();
> > }
> > init_error:;
> > }
> > }
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list