diff options
author | Dick Porter <dick@acm.org> | 2004-09-07 16:06:46 +0400 |
---|---|---|
committer | Dick Porter <dick@acm.org> | 2004-09-07 16:06:46 +0400 |
commit | 7a2d37d26383c5fed4ad4ae1339455856bbfdffb (patch) | |
tree | 6aa8c455868e5b25681424619535e96ac3a0a9f9 | |
parent | 9984dde0d9b4cea32b42e0092a150c14e491c5d0 (diff) |
2004-09-07 Dick Porter <dick@ximian.com>
* Process.cs: Throw documented exceptions when getting stdin,
stdout or stderr and they haven't been redirected. Check that
CreatePipe didn't fail, throw exceptions if it did. Close
redirected streams when the process is disposed, rather than rely
on the GC disposing them later. Makes timeline much happier,
because it could run out of file descriptors between GC
collections.
svn path=/branches/mono-1-0/mcs/; revision=33502
-rw-r--r-- | mcs/class/System/System.Diagnostics/ChangeLog | 10 | ||||
-rwxr-xr-x | mcs/class/System/System.Diagnostics/Process.cs | 36 |
2 files changed, 46 insertions, 0 deletions
diff --git a/mcs/class/System/System.Diagnostics/ChangeLog b/mcs/class/System/System.Diagnostics/ChangeLog index 98b95742e6e..7496fda092e 100644 --- a/mcs/class/System/System.Diagnostics/ChangeLog +++ b/mcs/class/System/System.Diagnostics/ChangeLog @@ -1,3 +1,13 @@ +2004-09-07 Dick Porter <dick@ximian.com> + + * Process.cs: Throw documented exceptions when getting stdin, + stdout or stderr and they haven't been redirected. Check that + CreatePipe didn't fail, throw exceptions if it did. Close + redirected streams when the process is disposed, rather than rely + on the GC disposing them later. Makes timeline much happier, + because it could run out of file descriptors between GC + collections. + 2004-09-06 Dick Porter <dick@ximian.com> * Process.cs: Make Dispose() actually dispose things. diff --git a/mcs/class/System/System.Diagnostics/Process.cs b/mcs/class/System/System.Diagnostics/Process.cs index a126d229587..e46ab5b0730 100755 --- a/mcs/class/System/System.Diagnostics/Process.cs +++ b/mcs/class/System/System.Diagnostics/Process.cs @@ -460,6 +460,10 @@ namespace System.Diagnostics { [MonitoringDescription ("The standard error stream of this process.")] public StreamReader StandardError { get { + if (error_stream == null) { + throw new InvalidOperationException("Standard error has not been redirected"); + } + return(error_stream); } } @@ -470,6 +474,10 @@ namespace System.Diagnostics { [MonitoringDescription ("The standard input stream of this process.")] public StreamWriter StandardInput { get { + if (input_stream == null) { + throw new InvalidOperationException("Standard input has not been redirected"); + } + return(input_stream); } } @@ -480,6 +488,10 @@ namespace System.Diagnostics { [MonitoringDescription ("The standard output stream of this process.")] public StreamReader StandardOutput { get { + if (output_stream == null) { + throw new InvalidOperationException("Standard output has not been redirected"); + } + return(output_stream); } } @@ -739,6 +751,9 @@ namespace System.Diagnostics { if(startInfo.RedirectStandardInput==true) { ret=MonoIO.CreatePipe(out stdin_rd, out stdin_wr); + if (ret == false) { + throw new IOException("Error creating standard input pipe"); + } } else { stdin_rd=MonoIO.ConsoleInput; /* This is required to stop the @@ -751,6 +766,9 @@ namespace System.Diagnostics { if(startInfo.RedirectStandardOutput==true) { ret=MonoIO.CreatePipe(out stdout_rd, out stdout_wr); + if (ret == false) { + throw new IOException("Error creating standard output pipe"); + } } else { stdout_rd=(IntPtr)0; stdout_wr=MonoIO.ConsoleOutput; @@ -759,6 +777,9 @@ namespace System.Diagnostics { if(startInfo.RedirectStandardError==true) { ret=MonoIO.CreatePipe(out stderr_rd, out stderr_wr); + if (ret == false) { + throw new IOException("Error creating standard error pipe"); + } } else { stderr_rd=(IntPtr)0; stderr_wr=MonoIO.ConsoleError; @@ -922,6 +943,21 @@ namespace System.Diagnostics { Process_free_internal(process_handle); process_handle=IntPtr.Zero; } + + if (input_stream != null) { + input_stream.Close(); + input_stream = null; + } + + if (output_stream != null) { + output_stream.Close(); + output_stream = null; + } + + if (error_stream != null) { + error_stream.Close(); + error_stream = null; + } } } base.Dispose (disposing); |