Skip to content

Instantly share code, notes, and snippets.

@KianYang-Lee
Created July 25, 2022 14:56
Show Gist options
  • Save KianYang-Lee/8c4b15e915fad715a7556a621075319f to your computer and use it in GitHub Desktop.
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
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