Console.WriteLine

R

Rick

I have a Windows exe app that runs with or without user intervention. When
it is running w/o user intervention the program is called from a DOS
windows, it's main form is set to visible=false and as it runs, I want to
write out certain events to the console. I've added
System.Console.WriteLine(mymessage) code, but the messages do not appear in
the DOS window where the program is running. Any suggestions?
Thanks,
Rick
 
M

MM

Rick said:
I have a Windows exe app that runs with or without user intervention. When
it is running w/o user intervention the program is called from a DOS
windows, it's main form is set to visible=false and as it runs, I want to
write out certain events to the console. I've added
System.Console.WriteLine(mymessage) code, but the messages do not appear in
the DOS window where the program is running. Any suggestions?
Thanks,
Rick
I was curious about this myself. The System.Console docs have this to say:
The Console class provides basic support for applications that read
characters from, and write characters to, the console. If the console
does not exist, as in a Windows-based application, writes to the console
are not displayed and no exception is raised.
 
W

William Stacey [MVP]

This is a classic problem with no great solution. As it is still a windows
app, there is no console attached. The DOS is not associated as a console
for your app. You could attach to that console, but finding the right
console (i.e. the one that started the app) is difficult. Most times, MS
and handle this with two programs. One is console app with a .com
extention. The other is a windows app with .exe extention. At a command
prompt the .com program will be run first. So depending on the command line
args, you could keep running console app or start the windows app.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top