Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
If I write this script in python and execute it in a UNIX shell, would this execute the command one at a time, or send all the commands?
Let's say the script is:
-----------------
#!/usr/bin/python3
import os
os.system('echo Hello')
os.system('echo Good day')
------------------
Would this execute the first command, and then execute the second command immediately afterwards?
How would i write a script to make it so that the os executes the first command, wait until it's done, then execute the second command?
I need to do this with commands that will take a long time to run, and I need to make it so that the next command waits until the previous one is done executing before starting.
3 Answers
- Anonymous5 years agoFavorite Answer
Why Python and not a shell script?
Yes the commands will be executed in sequence. If you need to set up a control you have the command
wait
to which you can add the the process ID pid....
- husoskiLv 75 years ago
Yes, os.system() waits until the command completes before returning a result. See the documentation at:
https://docs.python.org/2/library/os.html#os.syste...
(That's for Python 2.7. Scroll to the very top of that page and use the version drop-down if you're using another version.)
- brilliant_movesLv 75 years ago
Add this to your imports:
import time
Then insert at appropriate place:
time.sleep(1)