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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return message from Command Line utility

Status
Not open for further replies.

shavon

Programmer
Jun 18, 2001
102
0
0
CA
Good morning:

I am using a command line utility that generates a message when used in the DOS window. For instance, after it executes, it tells you if it was successful or if there was an error.

How can I get this message using it in VB? I am using the gwsend utility for sending Groupwise email. Thanks.
 
Good old DOS:
Redirect the output of the command to a file!
Lets assume your command is named DOIT.EXE

Kill "Output.Txt"
dummy = Shell("DOIT.EXE > Output.Txt", vbMinimizedFocus))

'Now Output.Txt contains the output of DOIT.EXE
'Maybe you have to wait here for execution

Open Output.Txt for input as #1
Line input t$

'Analyze contents
Close

Warning: You are trouble if Doit.Exe performs any kind of user interaction. E.g. if you start an xcopy which asks "Is this a file or directory?", then the program seems to hang.

If synchronization is a problem, use a batch, maybe its not elegant, but it works:

Open "C:\Temp\MyBatch.Bat" for output as #1
Print #1, "@echo off"
Print #1, "Kill C:\Temp\Ready.FLG"
Print #1, "Doit.Exe > Output.Txt"
Print #1, "Echo OK > C:\Temp\Ready.FLG"
Print #1, "Cls"
Print #1, "Exit"
Close 1
dummy = Shell("C:\Temp\MyBatch.Bat", vbMinimizedFocus")
Do while dir$("C:\Temp\Ready.FLG") =""
DoEvents()
Loop
'Now open Output.Txt and get the results...

By the way:
> always overwrites an existing file (if any)
>> appends to file








 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top