相关疑难解决方法(0)

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

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

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();
Run Code Online (Sandbox Code Playgroud)

如何获取命令的输出?

c# shell command prompt output

15
推荐指数
1
解决办法
3万
查看次数

在.NET中有效地重定向标准输出

我试图从.NET程序调用php-cgi.exe.我使用RedirectStandardOutput将输出作为流返回,但整个过程非常慢.

你对我如何能加快速度有任何想法吗?还有其他技术吗?

    Dim oCGI As ProcessStartInfo = New ProcessStartInfo()
    oCGI.WorkingDirectory = "C:\Program Files\Application\php"
    oCGI.FileName = "php-cgi.exe"
    oCGI.RedirectStandardOutput = True
    oCGI.RedirectStandardInput = True
    oCGI.UseShellExecute = False
    oCGI.CreateNoWindow = True

    Dim oProcess As Process = New Process()

    oProcess.StartInfo = oCGI
    oProcess.Start()

    oProcess.StandardOutput.ReadToEnd()
Run Code Online (Sandbox Code Playgroud)

.net c# cgi process

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×2

.net ×1

cgi ×1

command ×1

output ×1

process ×1

prompt ×1

shell ×1