在c#中怎么调用一个命令行程序,这个命令行程序有一些输出,类似于“正在。”,我如何获得这些信息呢

解决方案 »

  1.   

    输出重定向
    比如:运行cmd.exe,输入  ping www.csdn.net >>c:\pinglog.txt这样输出就被定向到c:\pinglog.txt,读取这个文件即可
      

  2.   

    或者启动process,然后读取StandardOutputProcess myProcess = new Process();
    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("Process_StandardOutput_Sample.exe" );
    myProcessStartInfo.UseShellExecute = false;
    myProcessStartInfo.RedirectStandardOutput = true;
    myProcess.StartInfo = myProcessStartInfo;
    myProcess.Start();StreamReader myStreamReader = myProcess.StandardOutput;
    // Read the standard output of the spawned process.
    string myString = myStreamReader.ReadLine();
    Console.WriteLine(myString);
    myProcess.Close();
      

  3.   

    参考这里
    http://blog.csdn.net/zhzuo/archive/2004/03/21/22024.aspx