首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >相当于shell_exec的C#

相当于shell_exec的C#
EN

Stack Overflow用户
提问于 2011-06-22 04:58:39
回答 3查看 2.4K关注 0票数 6

如何通过外壳执行命令,并使用C#以字符串形式返回完整的输出?

相当于PHP的shell_exec()

谢谢,进阶。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-06-22 05:07:23

MSDN documentation on Process.StandardOutput文档显示了一个示例

代码语言:javascript
复制
// 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();

您可能还想提取标准错误流。

票数 5
EN

Stack Overflow用户

发布于 2011-06-22 04:59:53

使用Process

票数 5
EN

Stack Overflow用户

发布于 2011-06-22 05:02:08

看看Process类Standard OutputStandard Error,以及OutputDataReceivedErrorDataReceived接收的事件。

有一个CodeProject article here,你可能会发现它很有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6431886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档