Link to home
Start Free TrialLog in
Avatar of Sorklin
Sorklin

asked on

Console output (STDOut for VB)?

Okay, I wrote a command line program with no forms (just a quick cludge) and I wanted to be able to output to the console some message.

I've searched quite a bit and haven't found anything that will let me print a simple string to the cmdline like I want.  The only way I've been able to do it is to use msgbox, but I don't want any windows involved.  Just return a result by command line.

Is there a simple way to do this that I'm missing?
Avatar of DennisBorg
DennisBorg

Avatar of hes
Also take a look here:
http://www.saurik.com/samples/

look at smpConsole
The trouble I've seen with this is that I've been unable to attach to a pre-existing command line window, only start a new console window.  At this point, I have not solved it or seen it solved.
Good point, Paul.

But how would one determine which pre-existing console window to target? One could have many open at the time, but all would have been spawned by COMMAND.COM or CMD.EXE

-Dennis Borg
That's part of the trouble.  The other part is that VB programs do not have any built in console function, they are compiled as GUI applications, not console apps.  They can allocate a new console easily enough, but there doesn't seem to be anyway to attach to an existing StdIn/StdOut the way one would when starting a program from a batch file or from the command prompt.

This is detailed here:
HOWTO: Attach a Console Window to Your Visual Basic Program

http://support.microsoft.com/support/kb/articles/Q171/6/54.asp
Quote:

If a Visual Basic application is started from a console application, the operating system automatically detaches it from the console, preventing the Visual Basic application from interacting with it. This article does not provide a method to prevent this from happening, but does demonstrate creating a new console window that your application can interact with. It also demonstrates running a console application (batch file, in this case) from Visual Basic, which utilizes the created console.
<Movie line; circa 1940s.. "Say it isn't so Joe">

Sad, but true.. <sigh>
Good info, Paul. Thank you for the input!
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Tim!
Neat hack!
Avatar of Sorklin

ASKER

Tim, I haven't tried it yet, but I will.  Sounds like what I want.
Avatar of Sorklin

ASKER

Very neat hack.  Where did you ever figure this one out?
Not my code I freely admit, I found it in an old question posted by mcrider I think. Gave it a go and it worked excellently. It is a handy tool to keep in the arsenal.
>It is a handy tool to keep in the arsenal.

A very good thing to know!
Avatar of Sorklin

ASKER

Exactly what this forum is for.  It would take me a thousand years to come up with something like this.  Thanks.