Re: [Mono-devel-list] System.Diagnostics.Process redirection

2005-07-05 Thread Colin JN Breame
On Monday 04 Jul 2005 17:05, John Bailo wrote:
 Colin JN Breame wrote:
 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.

 I tried it and got the exact same result

Thanks - glad to know it's not just me!  I'll register a bug.


 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
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] System.Diagnostics.Process redirection

2005-07-04 Thread John Bailo

Colin JN Breame wrote:


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.
 



I tried it and got the exact 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@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
   





 



___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] System.Diagnostics.Process redirection

2005-07-03 Thread John Bailo
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


Re: [Mono-devel-list] System.Diagnostics.Process redirection

2005-07-03 Thread Colin JN Breame
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@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
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list