5月23th

C#执行或调用cmd命令

DIY编程技术我来说两句!

string cmdStr = “第1行命令…” + Environment.NewLine +
“第2行命令…” + Environment.NewLine +
“第3行命令…” + Environment.NewLine +
“第4行命令…” + Environment.NewLine +
“exit”;
//设置命令行、参数
pro.StartInfo.FileName = “cmd.exe”;
pro.StartInfo.Arguments = ” /c”;
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.CreateNoWindow = true;
//启动CMD
pro.Start();
//运行命令
pro.StandardInput.WriteLine(cmdStr);
pro.WaitForExit();
MessageBox.Show(“ok”);

/c :执行后自动退出

本文出自:DIY博客园,链接:https://www.diybloghome.com/prology/12.html,转载请注明!