using console with a windows app

G

Guest

I have a VB app with a form under FW 1.1, sp1. In sub main, I do some setup
processing that may or may not result in some calls to:
Console.Writeline(...)
eventually, I do:
Application.Run(New Form1)

All this works. If the app is run by clicking the app's icon, the console
writes are discarded. If I run from a command prompt window via
app arg1 arg2 | more
I will see the console writes in the command window. But if I run via
app arg1 arg2
the console writes are discarded.

I would like to avoid piping to 'more' if possible. I guess what I want to
do is flush and close stdout before I do Application.Run(New Form1). But
Console.Out.Flush()
and/or
Console.Out.Close()
don't help.

I'm looking for a .net solution - not api's. Also, I have read some info
about making a console app and starting forms from it. I'd rather not go
that way - this app is a windows gui app that has a couple of troubleshooting
command line features. So, is there a .net way to close and flush stdout so
the text is visible in the command prompt window while the windowed app
continues to run?
 
S

Stoitcho Goutsev \(100\) [C# MVP]

AMercer,

There are two type of applications - console applications and GUI (windows)
applications.

Console application creates and attaches to the console a window (normally
with black background) that the program can write to and read from.

GUI applications on the other hand don't create and attach window to the
console. The console exist (the application can write to and read from) but
there is no window attached to display the output.

When you redirect the standard output to *more* you see the result because
*more* is a console application and you see the result on its console
window. This what *more* is meant to be used for.

The unfortunate part is that there is not managed API for creatting and
attaching window to the console neither to detach and close one. This can be
done with PInvoke and Win32 API.

You can create a console application that will show a console window and
then turn the application to GUI via creating the main form and calling
Application.Start. In this case the console window will be open at the whole
time.

You can create a GUI application and using PInvoke attach and then detach a
console window. This is not very good idea, is it?

You can create a GUI application and redirect the output to a log file or
you can create your own log window.
 

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