for TARGET_J2EE only:
[mono.git] / mcs / class / System / System.Diagnostics / Process.cs
index 76df18b87a334aeffb5a6347c2d3bc200c140b44..07ed17f498eeea26807abc464fa7e9ef98c0c6ad 100644 (file)
@@ -209,9 +209,8 @@ namespace System.Diagnostics {
                [MonitoringDescription ("Process identifier.")]
                public int Id {
                        get {
-                               if (pid == 0) {
+                               if (pid == 0)
                                        throw new InvalidOperationException ("Process ID has not been set.");
-                               }
 
                                return(pid);
                        }
@@ -262,9 +261,10 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The maximum working set for this process.")]
                public IntPtr MaxWorkingSet {
                        get {
-                               if(HasExited) {
-                                       throw new InvalidOperationException("The process " + ProcessName + " (ID " + Id + ") has exited");
-                               }
+                               if(HasExited)
+                                       throw new InvalidOperationException(
+                                               "The process " + ProcessName +
+                                               " (ID " + Id + ") has exited");
                                
                                int min;
                                int max;
@@ -291,28 +291,27 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The minimum working set for this process.")]
                public IntPtr MinWorkingSet {
                        get {
-                               if(HasExited) {
-                                       throw new InvalidOperationException("The process " + ProcessName + " (ID " + Id + ") has exited");
-                               }
+                               if(HasExited)
+                                       throw new InvalidOperationException(
+                                               "The process " + ProcessName +
+                                               " (ID " + Id + ") has exited");
                                
                                int min;
                                int max;
-                               bool ok=GetWorkingSet_internal(process_handle, out min, out max);
-                               if(ok==false) {
+                               bool ok= GetWorkingSet_internal (process_handle, out min, out max);
+                               if(!ok)
                                        throw new Win32Exception();
-                               }
-                               
-                               return((IntPtr)min);
+                               return ((IntPtr) min);
                        }
                        set {
-                               if(HasExited) {
-                                       throw new InvalidOperationException("The process " + ProcessName + " (ID " + Id + ") has exited");
-                               }
+                               if(HasExited)
+                                       throw new InvalidOperationException(
+                                               "The process " + ProcessName +
+                                               " (ID " + Id + ") has exited");
                                
-                               bool ok=SetWorkingSet_internal(process_handle, value.ToInt32(), 0, true);
-                               if(ok==false) {
+                               bool ok = SetWorkingSet_internal (process_handle, value.ToInt32(), 0, true);
+                               if (!ok)
                                        throw new Win32Exception();
-                               }
                        }
                }
 
@@ -320,7 +319,7 @@ namespace System.Diagnostics {
                 * element 0.
                 */
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern ProcessModule[] GetModules_internal();
+               private extern ProcessModule[] GetModules_internal(IntPtr handle);
 
                private ProcessModuleCollection module_collection;
                
@@ -328,10 +327,9 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The modules that are loaded as part of this process.")]
                public ProcessModuleCollection Modules {
                        get {
-                               if(module_collection==null) {
-                                       module_collection=new ProcessModuleCollection(GetModules_internal());
-                               }
-
+                               if (module_collection == null)
+                                       module_collection = new ProcessModuleCollection(
+                                               GetModules_internal (process_handle));
                                return(module_collection);
                        }
                }
@@ -486,6 +484,9 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The relative process priority.")]
                public ProcessPriorityClass PriorityClass {
                        get {
+                               if (process_handle == IntPtr.Zero)
+                                       throw new InvalidOperationException ("Process has not been started.");
+                               
                                int error;
                                int prio = GetPriorityClass (process_handle, out error);
                                if (prio == 0)
@@ -493,10 +494,14 @@ namespace System.Diagnostics {
                                return (ProcessPriorityClass) prio;
                        }
                        set {
-                               // LAMESPEC: not documented on MSDN for NET_1_1
                                if (!Enum.IsDefined (typeof (ProcessPriorityClass), value))
-                                       throw new InvalidEnumArgumentException ();
+                                       throw new InvalidEnumArgumentException (
+                                               "value", (int) value,
+                                               typeof (ProcessPriorityClass));
 
+                               if (process_handle == IntPtr.Zero)
+                                       throw new InvalidOperationException ("Process has not been started.");
+                               
                                int error;
                                if (!SetPriorityClass (process_handle, (int) value, out error))
                                        throw new Win32Exception (error);
@@ -523,6 +528,8 @@ namespace System.Diagnostics {
 
 #if NET_2_0
                [MonoNotSupported ("")]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               [MonitoringDescription ("The session ID for this process.")]
                public int SessionId {
                        get { throw new NotImplementedException (); }
                }
@@ -555,9 +562,8 @@ namespace System.Diagnostics {
                                         * null, assume the process
                                         * has exited
                                         */
-                                       if(process_name==null) {
+                                       if (process_name == null)
                                                throw new SystemException("The process has exited");
-                                       }
                                        
                                        /* Strip the suffix (if it
                                         * exists) simplistically
@@ -602,9 +608,9 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The standard error stream of this process.")]
                public StreamReader StandardError {
                        get {
-                               if (error_stream == null) {
+                               if (error_stream == null)
                                        throw new InvalidOperationException("Standard error has not been redirected");
-                               }
+
 #if NET_2_0
                                if ((async_mode & AsyncModes.AsyncError) != 0)
                                        throw new InvalidOperationException ("Cannot mix asynchronous and synchonous reads.");
@@ -622,9 +628,8 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The standard input stream of this process.")]
                public StreamWriter StandardInput {
                        get {
-                               if (input_stream == null) {
+                               if (input_stream == null)
                                        throw new InvalidOperationException("Standard input has not been redirected");
-                               }
 
                                return(input_stream);
                        }
@@ -636,9 +641,9 @@ namespace System.Diagnostics {
                [MonitoringDescription ("The standard output stream of this process.")]
                public StreamReader StandardOutput {
                        get {
-                               if (output_stream == null) {
+                               if (output_stream == null)
                                        throw new InvalidOperationException("Standard output has not been redirected");
-                               }
+
 #if NET_2_0
                                if ((async_mode & AsyncModes.AsyncOutput) != 0)
                                        throw new InvalidOperationException ("Cannot mix asynchronous and synchonous reads.");
@@ -656,18 +661,14 @@ namespace System.Diagnostics {
                [MonitoringDescription ("Information for the start of this process.")]
                public ProcessStartInfo StartInfo {
                        get {
-                               if(start_info==null) {
-                                       start_info=new ProcessStartInfo();
-                               }
-                               
-                               return(start_info);
+                               if (start_info == null)
+                                       start_info = new ProcessStartInfo();
+                               return start_info;
                        }
                        set {
-                               if(value==null) {
-                                       throw new ArgumentException("value is null");
-                               }
-                               
-                               start_info=value;
+                               if (value == null)
+                                       throw new ArgumentNullException("value");
+                               start_info = value;
                        }
                }
 
@@ -814,9 +815,8 @@ namespace System.Diagnostics {
                        int pid = GetPid_internal();
                        IntPtr proc = GetProcess_internal(pid);
                        
-                       if (proc == IntPtr.Zero) {
+                       if (proc == IntPtr.Zero)
                                throw new SystemException("Can't find current process");
-                       }
 
                        return (new Process (proc, pid));
                }
@@ -825,9 +825,8 @@ namespace System.Diagnostics {
                {
                        IntPtr proc = GetProcess_internal(processId);
                        
-                       if (proc == IntPtr.Zero) {
+                       if (proc == IntPtr.Zero)
                                throw new ArgumentException ("Can't find process with ID " + processId.ToString ());
-                       }
 
                        return (new Process (proc, processId));
                }
@@ -909,7 +908,7 @@ namespace System.Diagnostics {
                }
 
                public void Refresh ()
-               {
+               {
                        // FIXME: should refresh any cached data we might have about
                        // the process (currently we have none).
                }
@@ -937,9 +936,8 @@ namespace System.Diagnostics {
                                throw new InvalidOperationException ("UseShellExecute must be false when redirecting I/O.");
                        }
 
-                       if (startInfo.HaveEnvVars) {
+                       if (startInfo.HaveEnvVars)
                                throw new InvalidOperationException ("UseShellExecute must be false in order to use environment variables.");
-                       }
 
                        FillUserInfo (startInfo, ref proc_info);
                        try {
@@ -965,8 +963,6 @@ namespace System.Diagnostics {
                private static bool Start_noshell (ProcessStartInfo startInfo,
                                                   Process process)
                {
-                       if (Path.IsPathRooted (startInfo.FileName) && !File.Exists (startInfo.FileName))
-                               throw new FileNotFoundException  ("Executable not found: " + startInfo.FileName);
                        ProcInfo proc_info=new ProcInfo();
                        IntPtr stdin_rd, stdin_wr;
                        IntPtr stdout_wr;
@@ -1067,11 +1063,10 @@ namespace System.Diagnostics {
                                        MonoIO.Close (stderr_wr, out error);
                                }
 
-                               throw new Win32Exception (-proc_info.pid, 
-                                       "ApplicationName='"+startInfo.FileName+
-                                       "', CommandLine='"+startInfo.Arguments+
-                                       "', CurrentDirectory='"+startInfo.WorkingDirectory+
-                                       "', PATH='"+startInfo.EnvironmentVariables["PATH"]+"'");
+                               throw new Win32Exception (-proc_info.pid,
+                                       "ApplicationName='" + startInfo.FileName +
+                                       "', CommandLine='" + startInfo.Arguments +
+                                       "', CurrentDirectory='" + startInfo.WorkingDirectory + "'");
                        }
 
                        process.process_handle = proc_info.process_handle;
@@ -1125,10 +1120,8 @@ namespace System.Diagnostics {
                private static bool Start_common (ProcessStartInfo startInfo,
                                                  Process process)
                {
-                       if(startInfo.FileName == null ||
-                          startInfo.FileName == "") {
+                       if (startInfo.FileName == null || startInfo.FileName.Length == 0)
                                throw new InvalidOperationException("File name has not been set");
-                       }
                        
 #if NET_2_0
                        if (startInfo.StandardErrorEncoding != null && !startInfo.RedirectStandardError)
@@ -1148,40 +1141,35 @@ namespace System.Diagnostics {
                        }
                }
                
-               public bool Start() {
-                       bool ret;
-
+               public bool Start ()
+               {
                        if (process_handle != IntPtr.Zero) {
                                Process_free_internal (process_handle);
                                process_handle = IntPtr.Zero;
                        }
-                       ret=Start_common(start_info, this);
-                       
-                       return(ret);
+                       return Start_common(start_info, this);
                }
 
-               public static Process Start(ProcessStartInfo startInfo) {
+               public static Process Start (ProcessStartInfo startInfo)
+               {
+                       if (startInfo == null)
+                               throw new ArgumentNullException ("startInfo");
 
                        Process process=new Process();
-                       bool ret;
-
                        process.StartInfo = startInfo;
-                       ret=Start_common(startInfo, process);
-                       
-                       if(ret==true) {
-                               return(process);
-                       } else {
-                               return(null);
-                       }
+                       if (Start_common(startInfo, process))
+                               return process;
+                       return null;
                }
 
-               public static Process Start(string fileName) {
-                       return Start(new ProcessStartInfo(fileName));
+               public static Process Start (string fileName)
+               {
+                       return Start (new ProcessStartInfo (fileName));
                }
 
-               public static Process Start(string fileName,
-                                           string arguments) {
-                       return Start(new ProcessStartInfo(fileName, arguments));
+               public static Process Start(string fileName, string arguments)
+               {
+                       return Start (new ProcessStartInfo (fileName, arguments));
                }
 
 #if NET_2_0
@@ -1199,9 +1187,9 @@ namespace System.Diagnostics {
                }
 #endif
 
-               public override string ToString() {
-                       return(base.ToString() +
-                              " (" + this.ProcessName + ")");
+               public override string ToString()
+               {
+                       return(base.ToString() + " (" + this.ProcessName + ")");
                }
 
                /* Waits up to ms milliseconds for process 'handle' to