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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s