(以下内容是以参数启动程序的一个应用)

取得当前的系统信息,那么只需要调用 systeminfo 即可

//实例化一个进程类 
            Process cmd = newProcess();  
//获得系统信息,使用的是 systeminfo.exe 这个控制台程序 cmd.StartInfo.FileName = "systeminfo.exe";  
//将cmd的标准输入和输出全部重定向到.NET的程序里  
cmd.StartInfo.UseShellExecute = false; //此处必须为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();//关闭该进程

想做一个东西就是命令行执行一个东西,然后可以直接在一个TextBox实时看到结果。来自 http://blog.chinaunix.net/uid-26456800-id-4005397.html
有以下几个要点:
1.启动后用StandardInput.WrinteLine输入命令,就像你平时在CMD窗口里做的一样
         process.StandardInput.WriteLine("java -jar JSONRunner.jar tmp.json");    
2.使用   OutputDataReceived 事件,来处理当cmd得到新的输出时的行为,这里这个行为就是把内容更新到TextBox里
     process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
      
3.别忘了  process.BeginOutputReadLine(); 在开始cmd进程后。

4.因为这个等于是两个县城在操作同一个TextBox,所以会有一个warning. 用下面的语句忽略检查
         Control.CheckForIllegalCrossThreadCalls = false;
当然这个比较生硬。详细的分析和解决方法,请看这里:
http://blog.csdn.net/vodistr03/article/details/6658340 

5. 每次刷新TextBox把scroll bar滚动到底部。
    this.textBox1.SelectionStart =this.textBox1.Text.Length;
    this.textBox1.ScrollToCaret();

 

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Windows.Forms;
    9. using System.Diagnostics;
    10. using System.IO;
    11. namespace JSONMgr
    12. {
    13.     public partial class OutPutForm : Form
    14.     {
    15.         public Process process = null;
    16.         public OutPutForm()
    17.         {
    18.             InitializeComponent();
    19.         }
    20.   
    21.         private void OutPutForm_Shown(object sender, EventArgs e)
    22.         {
    23.             Control.CheckForIllegalCrossThreadCalls = false;
    24.             process = new Process();
    25.             process.StartInfo.FileName = "cmd.exe";
    26.             process.StartInfo.WorkingDirectory = ".";
    27.             process.StartInfo.UseShellExecute = false;
    28.             process.StartInfo.RedirectStandardInput = true;
    29.             process.StartInfo.RedirectStandardOutput = true;
    30.             process.StartInfo.CreateNoWindow = true;
    31.             //Process.Start("cmd.exe");
    32.             process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
    33.             process.Start();
    34.             process.StandardInput.WriteLine("java -jar JSONRunner.jar tmp.json");
    35.             
    36.             //process.StandardInput.WriteLine("exit");
    37.             process.BeginOutputReadLine();
    38.             //using (StreamWriter sw = new StreamWriter("output.log"))
    39.             //{
    40.             // sw.WriteLine(process.StandardOutput.ReadToEnd());
    41.             //}
    42.         }
    43.         private void OutputHandler(object sendingProcess,DataReceivedEventArgs outLine)
    44.         {
    45.             if (!String.IsNullOrEmpty(outLine.Data))
    46.             {
    47.                 StringBuilder sb = new StringBuilder(this.textBox1.Text);
    48.                 this.textBox1.Text = sb.AppendLine(outLine.Data).ToString();
    49.                 this.textBox1.SelectionStart =this.textBox1.Text.Length;
    50.                 this.textBox1.ScrollToCaret();
    51.             }
    52.         }
    53.         private void OutPutForm_FormClosing(object sender, FormClosingEventArgs e)
    54.         {
    55.             if (process != null)
    56.                 process.Close();
    57.         }
    58.     }
    59. }