Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Programmatically Wait For Shell Command To Finish Running?

Tags:

shell

smtp

vba

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?

like image 986
sooprise Avatar asked May 11 '11 17:05

sooprise


People also ask

Does a shell script wait for command to finish?

The bash wait command is a Shell command that waits for background running processes to complete and returns the exit status. Unlike the sleep command, which waits for a specified time, the wait command waits for all or specific background tasks to finish.

How do I sleep in a Linux shell script?

/bin/sleep is Linux or Unix command to delay for a specified amount of time. You can suspend the calling shell script for a specified time. For example, pause for 10 seconds or stop execution for 2 mintues. In other words, the sleep command pauses the execution on the next shell command for a given time.

How do I sleep in a bash script?

How to Use the Bash Sleep Command. Sleep is a very versatile command with a very simple syntax. It is as easy as typing sleep N . This will pause your script for N seconds, with N being either a positive integer or a floating point number.

How do you pause a bash script for 5 seconds?

sleep Command Bash Script Example Here is a simple example: #!/bin/bash echo "Hi, I'm sleeping for 5 seconds..." sleep 5 echo "all Done."


1 Answers

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

Set objShell = CreateObject("WScript.Shell")
result = objShell.Run(smtpPath & " " & emailInput, 0, true)
like image 175
Anders Lindahl Avatar answered Sep 28 '22 01:09

Anders Lindahl