c# 执行 shell 命令并获取结果

标签 c# shell command output prompt

<分区>

我正在执行命令提示符命令,如下所示:

string cmd = "/c dir" ; 
System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = cmd; 
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true; 
proc.Start();

如何获取命令的输出?

最佳答案

试试这个

string output = proc.StandardOutput.ReadToEnd();

关于c# 执行 shell 命令并获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15821016/

相关文章:

c# - ListView 中项目的动态 Id 属性

c# - XNA 4.0 打印到 Visual Studio 2012 控制台

bash - 访问 bash 中变量的函数定义时间而不是求值时间值

java - SWTBot - 等待消息框

c# - 为什么我会收到异常目录不为空?

c# - Azure Pipeline 中 csproj 文件内的 SignalR.Core 引用

linux - 更改Linux中的符号链接(symbolic link)

c# - ListView 上下文菜单上的命令绑定(bind)未触发(未找到)?

linux - 使用 Grep 扫描文件

C编程元素数组到sprintf()