2010/09/25

Calling another application or process from python

Incomplete and in progress as of 09/25/2010

example taken from gpodder program

I think this allows multiple threading according to the last line
def open_process(command_line):
        log('Running external command: %s', command_line)
        p = subprocess.Popen(command_line, shell=True)
        result = p.wait()
        if result == 127:
            log('Command not found: %s', command_line)
        elif result == 126:
            log('Command permission denied: %s', command_line)
        elif result > 0:
            log('Command returned an error (%d): %s', result, command_line)
        else:
            log('Command finished successfully: %s', command_line)
threading.Thread(target=open_process, args=(command_line,)).start()

No comments:

Post a Comment