How to display console output in the output window in Visual Studio Addin?
I am developing a Visual Studio plugin. It automatically generates and runs the command line. If I run the command in a shell, it can generate multiple logs while running.
However, I want to hide the shell window and display the logs in the Visual Studio output window. Is there a way to implement this?
Here's my code to run the command:
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();
+3
source to share
2 answers
according to this similar question
Change the application type to Windows before debugging. Without a console window, Console.WriteLine works like Trace.WriteLine. Don't forget that the app will reset to console type after debugging.
0
source to share
This can help:
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());
0
source to share