Python_2_Examples_and_Notes/20_subprocess.py

20 lines
403 B
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
subprocess.call(['ps', 'aux']) # Just exec.
lines = subprocess.check_output(['ls']) # Get output into vari
print type(lines)
print lines
# Popen for handle stds
handle = subprocess.Popen("ls", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) # True here can be a sec issue.
handle.stdout.read()