How to call an external program in python and retrieve the output and return code?

后端 未结 5 889
深忆病人
深忆病人 2020-11-27 15:42

How can I call an external program with a python script and retrieve the output and return code?

5条回答
  •  情深已故
    2020-11-27 16:18

    Look at the subprocess module: a simple example follows...

    from subprocess import Popen, PIPE
    
    process = Popen(["ls", "-la", "."], stdout=PIPE)
    (output, err) = process.communicate()
    exit_code = process.wait()
    

提交回复
热议问题