473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 28352
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future. I know that there is a way to send output by...
7
by: ~toki | last post by:
I have a full work app (server and client) that talk between two executables trought Console.WriteLine(); & Console.ReadLine(); I have the source code of the server. I need to make the client....
3
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and...
17
by: MumboJumbo | last post by:
Hi I have a really basic question hopefully some can help me with: Can you write a (i.e. one) C# project that works from the cmd line and gui? I seems if i write a GUI app it can't write to...
5
by: portroe | last post by:
Hi I am using console.Writeline in my simple program. I do not however see anything happening in the output window when I debug, there are also no error messages, Has anybody a tip on what...
4
by: Mythran | last post by:
I have the following code: public static void Main() { DoIt(); } private void DoIt() {
4
by: eduardorp1 | last post by:
I have a GUI application that needs to be invoked from the command line as well. It should work both as a GUI and as a console application. When I invoke it from the command line, it reads all...
1
by: TuckerRoth | last post by:
This is my first post on this site, so I don't know the rules. Please correct me if this gets to the wrong folks...etc. PROBLEM: Many of the apps that I am writing need to be able to run 2 ways:...
3
by: Curious | last post by:
I''ve created a simple Console Application in C#.NET (.NET 2.0), and I have the following code: Console.WriteLine("Now let us begin!"); However, the string, "Now let us begin!", never shows up...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.