On Sunday 03 July 2005 06:10, Colin JN Breame wrote: > Hello, > > Below is a program that on my system replicates an unexpected exit by the > mono runtime. > > The lines of interest are: > > stdout.WriteLine("1"); > p.StandardInput.WriteLine("hello world!"); > stdout.WriteLine("2"); > > As the program runs, it prints '1' but exit before '2' is printed >
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. 2. Have you stepped it through monodevelop? 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@lists.ximian.com > http://lists.ximian.com/mailman/listinfo/mono-devel-list _______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list