Created
July 25, 2022 14:56
-
-
Save KianYang-Lee/8c4b15e915fad715a7556a621075319f to your computer and use it in GitHub Desktop.
A simple demo on using `subprocess` module to generate subprocess to run shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from time import sleep | |
print("Program started...") | |
count = 0 | |
while count < 3: | |
sleep(5) | |
print("Calling subprocess...") | |
completed_process = subprocess.run("./check_users.sh", shell=True) | |
# You can then call attribute or methods of completedProcess here | |
completed_process_returncode = completed_process.returncode | |
print( | |
f"Returncode of round {count+1} of executing the process is: {completed_process_returncode}..." | |
) | |
count += 1 | |
print("All done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment