use Process class on Mono?
-
I need to ping IP with linux commands "ping xxx.xxx.xxx.xxx" . and run it with Mono on Linux server. Let's see my code...
Process P = new Process(); P.StartInfo.CreateNoWindow = true; P.StartInfo.FileName = "ping"; P.StartInfo.RedirectStandardOutput = true; P.StartInfo.Arguments = " 202.57.191.167"; P.Start(); P.WaitForExit(); string output = P.StandardOutput.ReadLine(); while (output != null && output!="") { Console.WriteLine(output); output = P.StandardOutput.ReadLine(); Thread.Sleep(500); } Console.ReadLine();
Then upload and run it,it throw exception..."Unhandled Exception: System.InvalidOperationException: UseShellExecute must be false when redirecting I/O. at System.Diagnostics.Process.Start_shell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] at System.Diagnostics.Process.Start () [0x00000] at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start () at ProcessLinuxCommands.Program.Main (System.String[] args) [0x00000]"
Could u help me what is this bug? Does Mono implement the Process class? thank =) -
I need to ping IP with linux commands "ping xxx.xxx.xxx.xxx" . and run it with Mono on Linux server. Let's see my code...
Process P = new Process(); P.StartInfo.CreateNoWindow = true; P.StartInfo.FileName = "ping"; P.StartInfo.RedirectStandardOutput = true; P.StartInfo.Arguments = " 202.57.191.167"; P.Start(); P.WaitForExit(); string output = P.StandardOutput.ReadLine(); while (output != null && output!="") { Console.WriteLine(output); output = P.StandardOutput.ReadLine(); Thread.Sleep(500); } Console.ReadLine();
Then upload and run it,it throw exception..."Unhandled Exception: System.InvalidOperationException: UseShellExecute must be false when redirecting I/O. at System.Diagnostics.Process.Start_shell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] at System.Diagnostics.Process.Start () [0x00000] at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start () at ProcessLinuxCommands.Program.Main (System.String[] args) [0x00000]"
Could u help me what is this bug? Does Mono implement the Process class? thank =)How about trying to set the
StartInfo.UseShellExecute
property tofalse
as the exception message indicates.?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook