[英]Process.Start - unable to send output to log file
我有以下代碼
var parameters =
string.Format("TestSuiteDefinitions.dll /include:{0} /out:{1} /err:{2} /xml:{3}", String.Join(",", args), OutputLog, ErrorLog, ResultLog);
var p = Process.Start(GetAssemblyDirectory() + @"\NUnit\nunit-console.exe", parameters);
這允許我從我的應用程序啟動一個單獨的進程啟動NUnit控制台與我的所需輸出。 問題是實際的NUnit輸出是寫入日志的唯一內容。 如果由於某些其他原因導致進程失敗,則在命令提示符級別從nunit-console.exe看到的命令輸出將丟失。
我試過添加
> CommandOutput.txt
要么
| CommandOutput.txt
在Process.Start參數字符串的末尾,但它拋出一個錯誤,所以不喜歡它。
誰能建議怎么做? 而且我無法使用標准輸出流的進程,因為調用進程需要在其他進程啟動后立即關閉,因此無法保持開放讀取和寫入流。
Process.Start
不會啟動shell,而只是生成一個進程。 因此,重定向和管道不起作用並不奇怪。 您可以將ProcessStartInfo
實例傳遞給Process.Start
,您可以在其中設置RedirectStandardOutput
並自己從p.StandardOutput
將其寫入文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.