Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting to shell from command line executable? (i.e. - ipconfig /h)

Status
Not open for further replies.

lwatanabe

Programmer
Jul 22, 2001
13
US
I'm looking to create a very simple executable that is designed to be executed from the command line with arguments.

I already know how to parse command line arguments, but how do I get the program to return text to the command prompt?

Take some one of the standard TCP/IP commands as an example ... typing "ipconfig /?" at the command prompt returns help text or "ping [ip]" returns text results to the command window at set intervals.

It sounds fairly simple, but I don't know how to do it. Any help would be greatly appreciated.

Thanks in advance!
 
Hi,

How about

ipconfig /h > %TEMP%\VB.TXT

Then open the %TEMP%\VB.TXT file and getting all the info from there?

Cheers,
Carl.
 
>It sounds fairly simple

It does, doesn't. Sadly, it isn't simple at all. Unless you have a burning requirement to do it the way you describe, I'd suggest that you consider Ogi's idea as a workable solution.

If you are still interested in doing it the hard way, just shout and I'll dig out my code that allows you to do it.
 
Thanks for the help, guys!

I'm seriously considering the console "help" features of the program. It was more of a cosmetic thing to make the project appear a little more complete from the command line perspective, anyway.

Once the project is completed I'll go back and add that functionality since I know how to do it, now. I know ... it's the hard way, but I'd rather do it the hard way than create workarounds.

I'll have to identify the window (command prompt) that is making the call, get it's handle, and write my output to that window's STDOUT. I was hoping to find a good way to do it without API calls but it seems like that is impossible without an ugly kluge.

Thanks for the help!
 
One you've got a console's handle and determined the STDIN, STDOUT and STDERR handles, writing to it is pretty easy (using the FileSystemObject, which knows about STDIN, STDOUT and STDERR). Reading stuff entered from the keyboard is also relatively straightforward. So the tricky bit is getting the legitimate handles. The method I use is to turn my VB application into a genuine console application. Once you've doen that it's all relatively starightforward (unless you want to read the output from other commands...)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top