Skip to content

Instantly share code, notes, and snippets.

@tokibito
Last active September 27, 2016 02:25
Show Gist options
  • Save tokibito/ba75798b8aba8467ea33ec6c5e265183 to your computer and use it in GitHub Desktop.
Save tokibito/ba75798b8aba8467ea33ec6c5e265183 to your computer and use it in GitHub Desktop.
subprocess call
tokibito@ubuntu:~$ cat main.py
import os
import subprocess
subprocess.call([os.environ['_'], "-V"])
tokibito@ubuntu:~$ python main.py
Python 2.7.6
tokibito@ubuntu:~$ tmp/venv/bin/python main.py
Python 3.4.3
tokibito@ubuntu:~$ cat main.py
import sys
import subprocess
subprocess.call([sys.executable, "-V"])
tokibito@ubuntu:~$ python main.py
Python 2.7.6
tokibito@ubuntu:~$ tmp/venv/bin/python main.py
Python 3.4.3
tokibito@ubuntu:~$ python -V
Python 2.7.6
(venv) tokibito@ubuntu:~$ python -V
Python 3.4.3
(venv) tokibito@ubuntu:~$ python
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call(["python", "-V"])
Python 3.4.3
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment