string dosCommand = "C:\\TEAMCE~1\\Express\\V53\\tc_menu\\tc_TcX_Configuration.bat";
Process p = new Process(); //创建进程对象
p.StartInfo.FileName = "C:\\WINDOWS\\system32\\cmd.exe"; //设定需要执行的命令
p.StartInfo.Arguments = " /C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
p.StartInfo.UseShellExecute = false; //不使用系统外壳程序启动
p.StartInfo.RedirectStandardInput = true; //重定向输入
p.StartInfo.RedirectStandardOutput = true; //重定向输出
p.StartInfo.RedirectStandardError = true; //重定向错误
p.StartInfo.CreateNoWindow = true; //不创建窗口 try
{
if (p.Start()) //开始进程
{
p.StandardInput.WriteLine("clearlocks -verbos");
string output = p.StandardOutput.ReadToEnd(); //读取进程的输出
string error = p.StandardError.ReadToEnd();
richTextBox1.Text = output + error;
}
}
catch
{ }
finally
{
if (p != null)
p.Close();
}程序里,我通过cmd.exe调用引用为dosCommand的批处理,然后再执行"clearlocks -verbose"这个语句,但是为什么最后输出到output的只有批处理的内容,而clearlocks -verbose执行的内容都没有显示,怎么办?
Process p = new Process(); //创建进程对象
p.StartInfo.FileName = "C:\\WINDOWS\\system32\\cmd.exe"; //设定需要执行的命令
p.StartInfo.Arguments = " /C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
p.StartInfo.UseShellExecute = false; //不使用系统外壳程序启动
p.StartInfo.RedirectStandardInput = true; //重定向输入
p.StartInfo.RedirectStandardOutput = true; //重定向输出
p.StartInfo.RedirectStandardError = true; //重定向错误
p.StartInfo.CreateNoWindow = true; //不创建窗口 try
{
if (p.Start()) //开始进程
{
p.StandardInput.WriteLine("clearlocks -verbos");
string output = p.StandardOutput.ReadToEnd(); //读取进程的输出
string error = p.StandardError.ReadToEnd();
richTextBox1.Text = output + error;
}
}
catch
{ }
finally
{
if (p != null)
p.Close();
}程序里,我通过cmd.exe调用引用为dosCommand的批处理,然后再执行"clearlocks -verbose"这个语句,但是为什么最后输出到output的只有批处理的内容,而clearlocks -verbose执行的内容都没有显示,怎么办?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货