我一直在試圖弄清楚爲什麼我不能使用>>(append)作爲我的p.StartInfo.Argument的一部分。當我刪除「>」它完美的作品,但當我嘗試使用「>」或「>>」我得到一個「不正確的參數」錯誤。我已經提前完成了,沒有>或>>編寫我的程序,只是將輸出存儲到一個字符串中,並稍後將其寫入文件。有人可以解釋爲什麼「>」或「>>」在這種情況下不起作用嗎?C#將過程結果重定向到文本文件
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "attrib.exe";
startInfo.Arguments = "/S *.jpg > mypics.txt";
p.Start();
我還沒有機會嘗試我們的建議,但我很想看看雙引號是否會讓我脫離使用重定向操作符。 – snapplex
這不是雙引號,因爲它是對「cmd.exe」的調用。我實際上推薦使用後者的版本(使用'StandardOutput.CopyTo'),它可以消除對「cmd.exe」的依賴。 – SlugFiller