public string CmdPc(string cmdinput)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
try
{
p.Start();
p.StandardInput.WriteLine(cmdinput);
p.StandardInput.WriteLine("exit");
string ss=p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
return ss;
}
catch
{
string ss = "命令执行失败";
return ss;
}
}
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
try
{
p.Start();
p.StandardInput.WriteLine(cmdinput);
p.StandardInput.WriteLine("exit");
string ss=p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
return ss;
}
catch
{
string ss = "命令执行失败";
return ss;
}
}
p.StartInfo.FileName = "cmd.exe"; //cmd 命令 就是控制台
p.StartInfo.UseShellExecute = false; //是否使用操作系统外壳程序启动进程
p.StartInfo.RedirectStandardInput = true; // 标准输入
p.StartInfo.RedirectStandardOutput = true; // 标准输出
p.StartInfo.CreateNoWindow = true; //无显示界面
try
{
p.Start(); //启动进程
p.StandardInput.WriteLine(cmdinput); // 执行命令脚本
p.StandardInput.WriteLine("exit"); // 关闭控制台
string ss=p.StandardOutput.ReadToEnd(); //将输出内容赋给变量ss
p.WaitForExit(); //如果这个外部程序没有结束运行则对其强行终止
p.Close(); // 关闭进程
return ss; // 方法返回值
}
catch
{
string ss = "命令执行失败";
return ss; // 异常返回值
}