vbscript. Any way to have a script wait for a shell command before continuing?

I have a vbscript which runs a shell command to create a zip file and then send it via email.

Problem is the rest of the vbscript runs before the shell command has finished, and the vbscript therefore tries to send a file which doesn’t exist yet.

I solved this by adding a ten second delay, but this is far from ideal (what if the shell command takes longer than ten seconds in the future)

Is there a way to have the vbscript detect when the shell command has finished it’s job and then continue?

the shell command is as follows…

"oShell.Run "pkzip “&Zipfile&” “&FileName”

Can you create a polling loop that checks for the existence of the file before continuing?

oShell is a WshShell object? If so, something like oShell.Run(“pkzip " &Zipfile&” “&FileName”, 0, true) should work. The 2nd argument to WshShell.Run indicates that pkzip executes in a hidden window; the 3rd argument tells the shell object to wait for the command to finish before returning (which is what you’re asking for).

FordPerfect Good idea that, I would have tried it, but 3WayGeek’s advice worked too so I went with that.
Thanks for the help guys :slight_smile:

The way I dealt with this in the past is have VB(not VBScript, but the principle is the same) execute a batch file, containing the Zip instruction, plus a second command to create a text file called done.txt - then have VB wait until it could find done.txt, before proceeding. It was dirty, but it did work.

Glad to hear it – I’ve written maybe 2 vbscripts in my life (I’m a C++/C/Assembler guy), but I know my way around the MSDN library.

It’s amazing how often the solution to a seemingly hard problem turns out to be an overload to a well known function that we just don’t use very often.

No worries, I had no idea that there was an overload like that. 3WayGeek had the better solution. Mine was just a hack.

Amen brother, amen.