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?
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.
/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 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.
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."
You could use WScript.Shell, and it's run method:
Set objShell = CreateObject("WScript.Shell")
result = objShell.Run(smtpPath & " " & emailInput, 0, true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With