简体   繁体   中英

How to display console output in output window in Visual Studio Addin?

I am developing a Visual Studio plugin. It will automatically generate and run a command line. If I run the command in the shell, it could generate some logs during 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();

according to this similar question

Change application type to Windows before debugging. Without Console window, Console.WriteLine works like Trace.WriteLine. Don't forget to reset application back to Console type after debugging.

This might 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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM