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?
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?
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
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
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.
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>
Sad, but true.. <sigh>
Good info, Paul. Thank you for the input!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks, Tim!
Neat hack!
ASKER
Tim, I haven't tried it yet, but I will. Sounds like what I want.
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!
A very good thing to know!
ASKER
Exactly what this forum is for. It would take me a thousand years to come up with something like this. Thanks.
http://www.planet-source-code.com/xq/ASP/txtCodeId.24474/lngWid.-1/qx/vb/scripts/ShowCode.htm
http://www.zektor8.co.uk/dotnet/articles/vbconsole/vbconsole.htm