3

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();
abatishchev
  • 98,240
  • 88
  • 296
  • 433
JDD
  • 51
  • 7
  • possible duplicate of [Redirect Console.Write... Methods to Visual Studio's Output Window While Debugging](http://stackoverflow.com/questions/2518509/redirect-console-write-methods-to-visual-studios-output-window-while-debuggi) – bowlturner Jun 24 '15 at 16:20

2 Answers2

0

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.

Community
  • 1
  • 1
bowlturner
  • 1,968
  • 4
  • 23
  • 35
0

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());
AzNjoE
  • 733
  • 3
  • 9
  • 18
  • 1
    `string.ToString()` really? – leppie Jun 24 '15 at 16:47
  • @leppie, was a simple mistake. Fixed. – AzNjoE Jun 24 '15 at 16:52
  • Thank for your reply. So if I use Debug.Write, the output will only display in the debug mode. Is there another way to display it? The plugin won't work in the debug/trace mode when users run it. – JDD Jun 24 '15 at 17:58
  • I'm not sure since I haven't dabbled into extending VS but here are some resources that may be of use: http://stackoverflow.com/questions/7773880/how-do-i-write-to-the-output-window-in-visual-studio-2010-addin https://msdn.microsoft.com/en-us/library/ht6z4e28.aspx https://msdn.microsoft.com/en-us/library/3hk6fby3.aspx https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsoutputwindow.aspx https://msdn.microsoft.com/en-us/library/bb166236.aspx – AzNjoE Jun 24 '15 at 18:35