Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write to a console window from a windows application?

Tags:

c#

Ever wondered how you could write out to a separate console window from your Windows application rather than writing to a log file? You might need to do that for a number of reasons – mostly related to debugging.

like image 999
Unknown Avatar asked Mar 30 '12 12:03

Unknown


People also ask

How do I change the console application in Windows?

Right click your project in the solution explorer and select properties. Then, under the "Application" tab change the "Output type" of your project from “Console Application” to “Windows Application.”


1 Answers

To do this programmatically, you can PInvoke the appropriate Win32 console functions (e.g. AllocConsole to create your own or AttachConsole to use another process's) from within your own code. This way you have the best control over what actually happens.

If you are OK with having a console window open alongside your other UI for the full lifetime of your process, you can simply change the project properties from within Visual Studio and choose "Console Application", simple as that:

VS Project settings

like image 133
Jon Avatar answered Nov 15 '22 06:11

Jon