我正在為命令行可執行文件編寫包裝器類。該exe接受來自stdin的輸入,直到我在命令提示符外殼中按ctrl + c為止,在這種情況下,它將根據輸入將輸出打印到stdout。我想模擬ctrl + c按下c#代碼,將kill命令發送到.Net進程對象。我試過調用Process.kill(),但是在該進程的StandardOutput StreamReader中似乎沒有給我任何東西??赡苡惺裁次易鰧Φ氖虑閱幔窟@是我要使用的代碼:ProcessStartInfo info = new ProcessStartInfo(exe, args);info.RedirectStandardError = true;info.RedirectStandardInput = true;info.RedirectStandardOutput = true;info.UseShellExecute = false;Process p = Process.Start(info);p.StandardInput.AutoFlush = true;p.StandardInput.WriteLine(scriptcode);p.Kill(); string error = p.StandardError.ReadToEnd();if (!String.IsNullOrEmpty(error)) { throw new Exception(error);}string output = p.StandardOutput.ReadToEnd();但是,即使我手動運行exe時從stdout獲取數據,輸出也始終為空。編輯:這是c#2.0 btw
3 回答

肥皂起泡泡
TA貢獻1829條經驗 獲得超6個贊
我實際上只是想出了答案。謝謝你們的回答,但事實證明,我要做的就是:
p.StandardInput.Close()
這使我產生的程序完成了從stdin的讀取并輸出了我所需要的。
- 3 回答
- 0 關注
- 1519 瀏覽
添加回答
舉報
0/150
提交
取消