Example #1
0
def runcmd(cmd,**kw):
    """run a command in an child process.

    accepts the same parameters as the `subprocess.Popen()` constructor.

    An additional keyword argument `continuation` will be called with
    the popen object as its argument when the process terminates.
    The default continuation simply logs the command and return code.

    TODO: give an example. (Use the source, Luke.)
    """
    cont = kw.pop("continuation",_finish)
    logging.debug("starting %r",cmd)
    p = Popen(cmd,**kw)
    p.cmd = cmd
    p.finish = cont
    return p