469,950 Members | 2,362 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Why Does Console.WriteLine() Not Write to Command Window?

I have a windows form app in C# in VS2005. In the "program.cs" file, I
take some command line arguments and use "Console.WriteLine("fsdfsd")
to give feedback to users. When I step through the program, the code
block is executing, but no text is written to the command line.

What might be causing this?

May 3 '07 #1
6 27305
Quite simply, windows apps don't connect to a console.

It can either be console or winform; Not both. This is part of the PE
header so is more Windows than .Net.

You could perhaps have 2 exes (one winform, one console).
Trace.WriteLine can be useful, as this will appear in the debugger by
default, or can be redirected.

Marc

May 3 '07 #2
Is just a thought but. why you dont try:

console.WriteLine("...");
Application.Run(new Form1);
-------------
An additional way is change the propertys in,out of the
System.Console, they are streams so you could put text files on

cheers,


May 3 '07 #3

put a breakpoint on the first line of your app and inspect
System.Console.Out. You'll see that it's ultimately a wrapper around
System.IO.Stream.NullStream.

((System.IO.StreamWriter)(((System.IO.TextWriter.S yncTextWriter)(System.Console.Out))._out)).BaseStr eam

Use a logging framework instead of console.writeline (I'd suggest
log4net).

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On 3 May 2007 11:56:25 -0700, jo*********@topscene.com wrote:
>I have a windows form app in C# in VS2005. In the "program.cs" file, I
take some command line arguments and use "Console.WriteLine("fsdfsd")
to give feedback to users. When I step through the program, the code
block is executing, but no text is written to the command line.

What might be causing this?
May 3 '07 #4
<jo*********@topscene.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
>I have a windows form app in C# in VS2005. In the "program.cs" file, I
take some command line arguments and use "Console.WriteLine("fsdfsd")
to give feedback to users. When I step through the program, the code
block is executing, but no text is written to the command line.

What might be causing this?
You've told the compiler that you have a windowed application. If you will
tell the compiler to compile it as a console app (which is somewhere in
Project Properties), you'll get a console window, and the forms will all
still work. This is a handy secret.

Or use System.Diagnostics.Debug.WriteLine(...) to write in the debug window
in VS2005 while the program runs.
May 4 '07 #5

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11*********************@c35g2000hsg.googlegro ups.com...
Quite simply, windows apps don't connect to a console.

It can either be console or winform; Not both. This is part of the PE
header so is more Windows than .Net.
Little-known fact: Actually it *can* be both. Take a Windows Forms app and
compile it as a console app, and you'll have a console window.

You can also use Win32 calls to create a console and attach a stream to it.
May 4 '07 #6
On Fri, 4 May 2007 00:37:33 -0400, "Michael A. Covington"
<lo**@ai.uga.edu.for.addresswrote:
>Little-known fact: Actually it *can* be both. Take a Windows Forms app and
compile it as a console app, and you'll have a console window.
Not really, it's actually a console application that pops up a window.
The original console window stays visible all the time.
--
http://www.kynosarges.de
May 4 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Boba | last post: by
7 posts views Thread by ~toki | last post: by
17 posts views Thread by MumboJumbo | last post: by
5 posts views Thread by portroe | last post: by
4 posts views Thread by eduardorp1 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.