Sunday, April 18, 2010

using the subprocess module

I was trying to automate some task involving shell programs, which actually a handful to type. As a lazy programmer, AUTOMATE WE MUST. Just turn out it involve with virtualenv, or rather virtualenv bootstrap script(that is another story altogether). So I do it in python. 

One of the thing added in python 2.6 is the subprocess module. To start use it


import subprocess


to use it, after the import, run this
subprocess.call(['programname','parameter1','parameter2'......])


for example to call some unix command
subprocess.call(['ls','-l'])
subprocess.call(['ps','-aux'])


or in my case, i use it to run setup.py in bootstrap script for virtualenv 


subprocess.call(['python','setup.py','install'])
subprocess.call(['easy_install','-U','packagename'])


Just a little writeup of subprocess, probably gonna use this a lot

No comments:

Post a Comment