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

后端 未结 5 887
深忆病人
深忆病人 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:09

    Following Ambroz Bizjak's previous comment, here is a solution that worked for me:

    import shlex
    from subprocess import Popen, PIPE
    
    cmd = "..."
    process = Popen(shlex.split(cmd), stdout=PIPE)
    process.communicate()
    exit_code = process.wait()
    

提交回复
热议问题