Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import shutil, subprocess
  2.  
  3. cmd = shutil.which("python3")
  4. runner = subprocess.run([cmd, "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # --> Python 3.7.3
  5. runner.resultcode # --> 0
  6.  
  7. 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
  8. runner.resultcode # --> 127
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement