如何从进程获取输出?

时间:2016-05-10 12:42:44

标签: c# cmd

所以这是我目前的代码:

 private void StartButton_Click(object sender, EventArgs e)
    {
        Download = "placeholdercommand"

        string CWD = System.IO.Directory.GetCurrentDirectory();        

        Process process = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();

        startInfo.Verb = "runas";                           ///launch as admin
        startInfo.FileName = "cmd.exe";                     ///launch cmd
        startInfo.Arguments = "/k cd /d " + CWD + "&" +     ///navigate cmd to CWD (/k = return)
                              Download + "&" +              ///give Download order to cmd
                              "exit";                       ///exit cmd

        process.StartInfo = startInfo;
        process.Start();
    }

现在我想让cmd窗口不可见,并在我的c#窗口中实时显示cmd工作。我该怎么做?

1 个答案:

答案 0 :(得分:0)

用此隐藏

info.WindowStyle=ProcessWindowStyle.Hidden;

获取输出

while (!process.StandardOutput.EndOfStream)
{
    string Line = process.StandardOutput.ReadLine();
}
相关问题