How To Programmatically Wait For Shell Command To

2019-01-28 01:09发布

问题:

I am sending emails in a program like so:

Call Shell(smtpPath, emailInput...)

This works great, except if I call the function twice, the function runs the first time, calls the shell command, then the function runs again, and calls the shell command again, but the first shell command is not completed, so there is an error because the second shell command is trying to use the same smtp file as the first one (that is still in use).

How can I make the function wait until the shell command has finished running?

Addendum: Or is there a way I can see if the file is being used, and if it is, sleep it, then try again?

回答1:

You could use WScript.Shell, and it's run method:

Set objShell = CreateObject("WScript.Shell")
result = objShell.Run(smtpPath & " " & emailInput, 0, true)


标签: shell vba smtp