【发布时间】:2010-10-29 12:30:03
【问题描述】:
我需要做两件事:运行一个批处理文件(工作正常),并运行一个命令(不工作)。 该命令的方法引发异常“找不到文件”。如果我打开一个 cmd 窗口,然后输入命令,它会完美运行。
private static void Rescan()
{
//System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("DEVCON ReScan");
//psi.RedirectStandardOutput = true;
//psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//psi.UseShellExecute = false;
//System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "DEVCON ReScan";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
System.IO.StreamReader myOutput = proc.StandardOutput;
proc.WaitForExit(4000);
if (proc.HasExited)
{
string output = myOutput.ReadToEnd();
FileIO.WriteLog(_writePath, output);
}
}
注释的代码也会抛出同样的异常。
【问题讨论】:
标签: c# .net command-line batch-file