The*_*ask 5 .net c# cmd shell-exec
如何通过shell执行命令并使用C#将完整输出作为字符串返回?
相当于PHP的shell_exec().
谢谢,先进.
小智 5
有关Process.StandardOutput文档的MSDN文档显示了一个示例
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
您可能还希望提取标准错误流。
| 归档时间: |
|
| 查看次数: |
1664 次 |
| 最近记录: |