首页  编辑  

执行Dos命令并得到输出结果

Tags: /C#/进程、线程处理/   Date Created:

using System . Diagnostics;

private void button1_Click( object sender , EventArgs e)

{

    Process vProcess = new Process ();

   vProcess . StartInfo . FileName = "cmd.exe" ;

   vProcess . StartInfo . UseShellExecute = false ;

   vProcess . StartInfo . RedirectStandardInput = true ;

   vProcess . StartInfo . RedirectStandardOutput = true ;

   vProcess . StartInfo . RedirectStandardError = true ;

   vProcess . StartInfo . CreateNoWindow = false ;

   vProcess . Start();

   vProcess . StandardInput . WriteLine( @"dir d:\" );

   vProcess . StandardInput . WriteLine( "exit" );

   textBox1 . Text = vProcess . StandardOutput . ReadToEnd();

   vProcess . Close();

}