Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import shutil, subprocess
- cmd = shutil.which("python3")
- runner = subprocess.run([cmd, "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # --> Python 3.7.3
- runner.resultcode # --> 0
- runner = subprocess.run([cmd, "--version"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # --> stderr bc shell=True is similar to calling `sh python3 --version` which will error
- runner.resultcode # --> 127
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement