![](/img/trans.png)
[英]How to pass output of separate console window to Visual Studio output window?
[英]How to display console output in output window in Visual Studio Addin?
我正在開發一個Visual Studio插件。 它將自動生成並運行命令行。 如果我在shell中運行該命令,它可能會在運行期間生成一些日志。
但是,我想隱藏shell窗口並在Visual Studio輸出窗口中顯示日志。 有沒有辦法實現這個?
這是我運行命令的代碼:
var process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c"+command;
process.Start();
根據這個類似的問題
調試前將應用程序類型更改為Windows。 如果沒有Console窗口,Console.WriteLine就像Trace.WriteLine一樣工作。 調試后不要忘記將應用程序重置回Console類型。
這可能有所幫助:
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.startInfo.RedirectStandardOutput = true;
process.startInfo.RedirectStandardError = true;
StreamReader stringBackFromProcess = process.StandardOutput;
Debug.Write(stringBackFromProcess.ReadToEnd());
// or
Console.Write(stringBackFromProcess.ReadToEnd());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.