Process cmd = new Process();
string result = cmd.StandardOutput.ReadToEnd();

解决方案 »

  1.   

    Process cmd = new Process();
    cmd.StartInfo.FileName = "";
    cmd.StartInfo.UseShellExecute = false;  
    cmd.StartInfo.RedirectStandardInput = true;
    cmd.StartInfo.RedirectStandardOutput = true;  
    cmd.StartInfo.CreateNoWindow = true;
    cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    cmd.Start();  
    this.textBox1.Text = cmd.StandardOutput.ReadToEnd();
    cmd.WaitForExit();
    cmd.Close();
      

  2.   

    Process cmd = new Process();
    cmd.Start();
    string result = cmd.StandardOutput.ReadToEnd();
      

  3.   

    引用错了 ,是这个方法 我试了 每次在readtoend的时候就已经结束了 没反应了 
      

  4.   

    呵呵,这个可能更好点吧。
      //用于执行dos命令的方法
            private string Execute(string dosCommand)
            {
                Thread.Sleep(150);
                string output = "";
                Process process = new Process();
                try
                {
                    process.StartInfo.WorkingDirectory = @"C:\WINDOWS\system32";
                    process.StartInfo.FileName = "cmd.exe";
                    process.StartInfo.Arguments = "/c " + dosCommand;
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardInput = true;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;
                    process.StartInfo.CreateNoWindow = true;
                    process.Start();
                    process.WaitForExit(1);
                    output = process.StandardError.ReadToEnd();                
                }
                catch (Exception ex)
                {
                    output = ex.Message;
                }
                if (process != null)
                    process.Close();
                return output;
            }
      

  5.   

               
    output = process.StandardOutput.ReadToEnd();
    output += process.StandardError.ReadToEnd(); 没试过,可能会报错。
      

  6.   


    还不是行,也在readtoend那个地方就不动了
      

  7.   


    在ReadToEnd()之前启动cmdProcess cmd = new Process();
    cmd.Start();
    string result = cmd.StandardOutput.ReadToEnd();
    cmd.WaitForExit();
      

  8.   

    我是照猫画虎,我也不知道参数设置的对不对. 已经start了 但是...
      

  9.   

     Process cmdProc = new Process();
                cmdProc.StartInfo.FileName = "your exe file name";
                cmdProc.StartInfo.UseShellExecute = false;
                cmdProc.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
                cmdProc.StartInfo.Arguments = "your argument type here";
                cmdProc.StartInfo.CreateNoWindow = true;
                cmdProc.StartInfo.RedirectStandardOutput = true;
                cmdProc.OutputDataReceived += (s, e) =>
                    {
                        Console.WriteLine(e.Data);
                    };
                cmdProc.Start();
                cmdProc.BeginOutputReadLine();关键的几句: //输出重定向
     cmdProc.StartInfo.RedirectStandardOutput = true;
     //注册输出变化事件
     cmdProc.OutputDataReceived += (s, e) =>
                    {
                        Console.WriteLine(e.Data);
                    };
      //开启进程
      cmdProc.Start();
      //开启之后,开始读取输出
      //如果有输出,你设置断点可看到Console.WriteLine(e.Data);不停被调用.
      cmdProc.BeginOutputReadLine();
      

  10.   


    s和e是什么东东?object EventArgs?
    还有 你这是用Linq写的吗?
      

  11.   

    看不到 任何输出
    调试的时候他给了一个 
    pro.ExitCode异常和pro.ExitTime异常.
      

  12.   

    faint lz把你代码贴出来看看。
      

  13.   

    我也对此感兴趣呵呵 check
      

  14.   

    http://blog.csdn.net/sxldfang/archive/2010/10/22/5959873.aspx
      

  15.   

                string str = "";
                lblmanager.Text = "";
                Process pro = new Process();
                pro.StartInfo.FileName = "cmd.exe";
                pro.StartInfo.UseShellExecute = false;
                pro.StartInfo.RedirectStandardInput = true;
                pro.StartInfo.RedirectStandardOutput = true;
                pro.StartInfo.RedirectStandardError = true;
                pro.StartInfo.CreateNoWindow = true;
                pro.Start();            if (textBox1.Text == "")
                {
                    MessageBox.Show("请输入指令");
                    return;
                }
                else
                {
                    pro.StandardInput.Write("@echo off");
                    pro.StandardInput.Write(textBox1.Text);
                    pro.StandardInput.Write("Exit");
                  Console.WriteLine( pro.StandardOutput.ReadToEnd());
                 
                    pro.WaitForExit(1);
                    pro.Close();
                }
    这是我的源码  大家帮我看下 有什么错!!!!!
      

  16.   

    我空间里有个经典的Delphi版的