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?
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).
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.
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.