By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,777 Members | 1,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,777 IT Pros & Developers. It's quick & easy.

Console Window

P: n/a
I am trying to figure out how to create a console window but cannot figure
out how to do this. I know it can be done since the C# and VB console
template projects do this but I see no code on how this is done.

The only thing I can think of is that there is hidden code to spawn cmd.exe?
Then they somehow direct console.read and console.write calls to the spawned
process.

Any thoughts (and some sample code) would be greatly appreciated.

- Jason
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jason,
I am trying to figure out how to create a console window but cannot figure
out how to do this. I know it can be done since the C# and VB console
template projects do this but I see no code on how this is done.


Windows creates the console window, if needed, when you run a console
application. There's no code needed in the application itself to do
this.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

P: n/a
Hi, Jason

you might want to check
ms-help://MS.NETFrameworkSDKv1.1/cpguidenf/html/cpconbuildingconsoleapplicat
ions.htm in Framework Help, or look for Console class.
Alternatively you can use Win32 API, like GetConsoleWindow() to attach
system console.
Platform SDK has also wealth of information on what is possible.

What exactly you want to achieve?

If you want just to open console window - compile application as console
application.

HTH
Alex

"Jason Callas" <Ja*******@hotmail.com> wrote in message
news:OM**************@tk2msftngp13.phx.gbl...
I am trying to figure out how to create a console window but cannot figure
out how to do this. I know it can be done since the C# and VB console
template projects do this but I see no code on how this is done.

The only thing I can think of is that there is hidden code to spawn cmd.exe? Then they somehow direct console.read and console.write calls to the spawned process.

Any thoughts (and some sample code) would be greatly appreciated.

- Jason

Jul 21 '05 #3

P: n/a
I am aware that you can just create a console application but that does not
work for my purposes.

I am writing a windows service that COULD be run as a standalone application
by passing a command-line argument. In that case (while in the IDE) I would
want a console window to be opened to handle input and output.

I'm guessing I could always just change the output type of the project to
Console while developing and change it back to Windows when I want to
release it.

- Jason

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi, Jason

you might want to check
ms-help://MS.NETFrameworkSDKv1.1/cpguidenf/html/cpconbuildingconsoleapplicat ions.htm in Framework Help, or look for Console class.
Alternatively you can use Win32 API, like GetConsoleWindow() to attach
system console.
Platform SDK has also wealth of information on what is possible.

What exactly you want to achieve?

If you want just to open console window - compile application as console
application.

HTH
Alex

"Jason Callas" <Ja*******@hotmail.com> wrote in message
news:OM**************@tk2msftngp13.phx.gbl...
I am trying to figure out how to create a console window but cannot figure out how to do this. I know it can be done since the C# and VB console
template projects do this but I see no code on how this is done.

The only thing I can think of is that there is hidden code to spawn

cmd.exe?
Then they somehow direct console.read and console.write calls to the

spawned
process.

Any thoughts (and some sample code) would be greatly appreciated.

- Jason


Jul 21 '05 #4

P: n/a
Jason Callas <Ja*******@hotmail.com> wrote:
I am aware that you can just create a console application but that does not
work for my purposes.

I am writing a windows service that COULD be run as a standalone application
by passing a command-line argument. In that case (while in the IDE) I would
want a console window to be opened to handle input and output.

I'm guessing I could always just change the output type of the project to
Console while developing and change it back to Windows when I want to
release it.


If you want to create a console optionally, you can use WinConsole:
http://www.codeproject.com/csharp/winconsole.asp

I believe there are a number of libraries like this available, so you
might want to shop around.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.