Running shell cmds from python
This is done using python's subprocess module. To run a cmd and just get the return code returned, use subprocess.call(). Internally this function uses Popen(), so its arguments are the same as for the Popen constructor (see below). For example: retval = subprocess.call(args = """find . -maxdepth 2 -empty -exec rm {} \;""", shell = True, stdout = None) If you need to PIPE in/output data between caller- and sub-process, create a Popen() instance and call communicate() on it. For example, the equivalent of ps aux | grep my_daemon_name will be: # execute cmd "ps aux" p1 = Popen(["ps", "aux"], stdout=PIPE) # execute cmd "grep my_daemon_name", with cmd's stdin set to stdout of previous "ps aux" cmd p2 = Popen(["grep", "my_daemon_name"], stdin=p1.stdout, stdout=PIPE) # retrieve the stdout data from grep output = p2.communicate()[0] See also PyMOTW for more examples. class subprocess...