怎么在程序中让CMD自动执行命令,急急急?
Process[] process = Process.GetProcessesByName( "KVMonXP.kxp ");
int pid = process[0].Id;
MessageBox.Show(pid.ToString(), " ");
ProcessStartInfo cmd = new ProcessStartInfo();
cmd.FileName = "cmd ";
cmd.Arguments= "taskkill /pid "+pid + "/t ";
cmd.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(cmd);
我把这段代码放到窗体的载入事件里,编译通过,且可以正常运行,但就是不执行 "taskkill /pid "+pid + "/t "命令,而是只弹出CMD窗口来,请问要怎么样才能让CMD自动运行那命,谢谢!
------解决方案--------------------我是个新手,下面这段代码可能对你会有所帮助
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
//p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine( "del d:\\123.txt ");
p.StandardInput.WriteLine( "exit ");