當我通過執行過程,並試圖重定向輸出/錯誤,我得到以下錯誤:的Process.Start()拋出一個「拒絕訪問」錯誤
System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Diagnostics.Process.CreatePipe(SafeFileHandle& parentHandle, SafeFileHandle& childHandle, Boolean parentInputs)
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
...
出了什麼問題?這裏是一個攝製:
string path = "C:\\batch.cmd";
using (Process proc = new Process())
{
bool pathExists = File.Exists(path);
if(!pathExists) throw new ArgumentException("Path doesnt exist");
proc.StartInfo.FileName = path;
proc.StartInfo.WorkingDirectory = workingDir.FullName;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start(); //Exception thrown here
proc.WaitForExit();
}
如果您執行'Console.Writeline(File.Exists(path));'?同樣的例外? – tomfanning 2011-12-17 22:45:09
您確定您有權訪問「路徑」中的文件嗎? – 2011-12-17 22:45:20
proc.Start()引發異常。如果我檢查路徑,它存在:bool pathExists = File.Exists(path); \t \t \t \t如果 \t \t \t \t { \t \t \t \t \t拋出新的ArgumentException( 「犯規存在路徑」)(pathExists!); \t \t \t \t} – Gjorgji 2011-12-17 22:49:09