Python subprocess examples

Here is the code for testing subprocess in python,

When this python program runs,the output will be send to standard output,stdout . For managing process Python 2.4 provides a special module called – subprocess and a class called Popen.

import subprocess
p = subprocess.Popen('df -h',shell=True, stdout=subprocess.PIPE)
out,err = p.communicate()
print out


[root@devine ~]# ./
Filesystem Size Used Avail Use% Mounted on
18G 3.5G 13G 22% /
tmpfs 497M 276K 497M 1% /dev/shm
/dev/sda1 485M 33M 428M 8% /boot