2015-09-21 38 views
-2

此代碼與ipconfig.exe配合良好,但我沒有收到任何與我的目標應用程序。無法從控制檯進程獲得輸出

Process p = new Process(); 
p.StartInfo.RedirectStandardError = true; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.RedirectStandardInput = true; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
p.StartInfo.FileName = "miner.exe"; 
p.StartInfo.Arguments = command; 
p.EnableRaisingEvents = true; 

p.OutputDataReceived += OutputDataReceived; 
p.ErrorDataReceived += ErrorDataReceived; 

p.Start(); 
p.BeginOutputReadLine(); 
p.StandardInput.Close(); 

有人可以告訴什麼可能是錯的,我該怎麼辦?目標應用程序是用C++編寫的,我認爲使用printf輸出。在論壇上,我看到一個人說,他不能讓這個應用程序與Linux中的管道工作。

+0

應該編寫C++程序控制臺上的東西?如果是註釋掉CreateNoWindow行並再次嘗試 – Taleeb

+0

如果正常運行(手動)它顯示在控制檯窗口中運行的文本行 –

+0

您已寫入p.StartInfo.CreateNoWindow = true和p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; ...所以沒有創建控制檯窗口 – Taleeb

回答

0

代碼看起來不錯。

如果進程不輸出任何內容到標準輸出,您將無法捕獲任何內容。

你可以驗證它是程序的行爲,並通過使用Windows或管道輸出現有的輸出重定向到一些其他程序的Windows/* nix中在你的代碼沒有錯誤 -

tool.exe > output.txt 
tool.exe | more 
+0

經過測試,文件已創建,但沒有任何內容。但如果我正常運行應用程序,我在窗口中看到文本!應該有辦法得到這個文本))) –