Question:Which of the following code samples will execute a command-line program in C# and return its STD OUT results? 

A System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProcess.StartInfo.FileName = strCommand; pProcess.StartInfo.Arguments = strCommandParameters; pProcess.StartInfo.UseShellExecute = false; pProcess.StartInfo.RedirectStandardOutput = true; pProcess.Start(); string strOutput = pProcess.StandardOutput.ReadToEnd(); pProcess.WaitForExit(); 

B Process p = new Process(); p.StartInfo.UseShellExecute = true p.StartInfo.RedirectStandardOutput = false p.StartInfo.FileName = "YOURBATCHFILE.bat"; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); 

C System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("program_to_call.exe"); psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; psi.UseShellExecute = false; System.Diagnostics.Process proc System.Diagnostics.Process.Start(psi);; System.IO.StreamReader myOutput = proc.StandardOutput; proc.WaitForExit(2000); if (proc.HasExited) { string output = myOutput.ReadToEnd(); } 

D System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProcess.StartInfo.FileName = strCommand; pProcess.StartInfo.Arguments = strCommandParameters; pProcess.StartInfo.UseShellExecute = false; pProcess.StartInfo.RedirectStandardOutput = true; pProcess.StartInfo.WorkingDirectory = strWorkingDirectory; pProcess.Start(); string strOutput = pProcess.StandardOutput.ReadToEnd(); pProcess.WaitForExit(); 

+ Answer
+ Report
Total Preview: 747

Copyright © 2024. Powered by Intellect Software Ltd