How do I tell when a Shelled Process ends?

M

Mac Lingo

I've an application that starts an FTP call with the Shell Command which
sends its output to a file. The Shell command of course returns a Process
Id number. There is probably a way to use this Process Id to figure out
that process is finished, so I can collect the output and go on with the
program. But I don't know how.

One obvious way is to wait for the file that was output to be found by a Dir
command. By that process seems to hang sometimes. So I thought I'd see if
there was a way go figure out if the process was finished directly.

Anyone out there know how to do this?

Thanks,
Mac
 
R

Robert Bruce

Mac Lingo said:
I've an application that starts an FTP call with the Shell Command which
sends its output to a file. The Shell command of course returns a Process
Id number. There is probably a way to use this Process Id to figure out
that process is finished, so I can collect the output and go on with the
program. But I don't know how.

One obvious way is to wait for the file that was output to be found by a
Dir command. By that process seems to hang sometimes. So I thought I'd
see if there was a way go figure out if the process was finished directly.

Anyone out there know how to do this?

The easiest way I've found is to create a Windows shell object and execute
its Run method which has a third param that you can use to tell it only to
return to processing when the shelled operation has finished.
http://msdn2.microsoft.com/en-us/library/d5fk67ky.aspx

Sub test()
Const HIDE_WINDOW As Long = 0
Dim objShell As Object
Set objShell = CreateObject("WScript.Shell")
objShell.Run "C:\test.bat", HIDE_WINDOW, True
Set objShell = Nothing
End Sub

HTH

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top