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

How to call a non-VB application (a "shell") from within VB

Status
Not open for further replies.

jmk2z

Programmer
Oct 29, 2002
18
US
Do you know how to call a non-VB application (a "shell") from within VB and return the output (stderr or stdout) of the non-VB application to the VB application. Someone attempted to do this with the CreateProcess function and it does not work. The -V option to the mqfta.exe executable causes mqfta to produce verbose output which I want to capture in the log.

Here is how is is currently done:

'Set executable variable for MQFTA

sCommand = sCustomDir & "\mqfta.exe -m" & sQmanager & " -q" & sQueue _
& " -f" & sFileWPath & " -A" & sAppid & " -I" & sIntid & " -V >>" & fErrorlog

'Send file via MQFTA

sMessage = "MESSAGE: SENDING FILE TO MQFTA: " & vbCrLf & sCommand & vbNewLine
fErrorlog.Write Now & " " & sMessage
ret& = CreateProcess(vbNullString, sCommand, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, vbNullString, start2, proc2)
sMessage = "MQFTA Ended with Return Code: " & ret& & vbCrLf
fErrorlog.Write Now & " " & sMessage
 
Thanks venom3249. ShellExecute was tried. BTW, jmk27 actually posted the original of this thread on my behalf, that's why you see my handle responding rather than his.

ShellExecute and CreateProcess essentially have the same difficulty. They provide no means for streaming output from the called application back into the VB program. In addition, if you need (and I do) to specifically determine when that newly-launched application has been terminated, then you must use the CreateProcess function.

I tried using pipes as well, to get a handle in the input and output streams, but do not think I implemented this correctly. If anyone can provide a code snipet that accomplishes the above I'd greatly appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top