在windows环境下,命令行程序为cmd.exe,是一个32位的命令行程序,微软Windows系统基于Windows上的命令解释程序,类似于微软的DOS操作系统。输入一些命令,cmd.exe可以执行,比如输入shutdown -s就会在30秒后关机。总之,它非常有用。打开方法:开始-所有程序-附件 或 开始-寻找-输入:cmd/cmd.exe 回车。它也可以执行BAT文件。
下面介绍使用C#程序调用cmd执行命令:
代码:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Diagnostics; 7 8 namespace CmdDemo 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 Console.WriteLine("请输入要执行的命令:"); 15 string strInput = Console.ReadLine(); 16 Process p = new Process(); 17 //设置要启动的应用程序 18 p.StartInfo.FileName = "cmd.exe"; 19 //是否使用操作系统shell启动 20 p.StartInfo.UseShellExecute = <