如何解决C#相当于shell_exec
| 如何通过Shell执行命令并使用C#将完整的输出作为字符串返回? 等效于PHP的shell_exec()。 谢谢,谢谢。解决方法
有关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();
您可能还希望提取标准错误流。
, 使用流程类
, 查看Process类Standard Output和Standard Error,以及OutputDataReceived和
ErrorDataReceived收到的事件。
这里有一个CodeProject文章,您可能会发现有帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。