How to run a python script from another python script and get the returned status code?

前端 未结 2 1846
有刺的猬
有刺的猬 2021-01-12 16:20

I\'m relatively new to both Python and bash. However, I am finding Python much more intuitive and easier than bash. I have a few bash scripts I have managed to cobble togeth

相关标签:
2条回答
  • 2021-01-12 16:36

    Using subprocess module

    master.py

    import subprocess
    retcode = subprocess.call(["/usr/bin/python", "/path/to/test.py"])
    print "Return code of test.py is ", retcode
    
    0 讨论(0)
  • 2021-01-12 16:47

    I would suggest you to look at the subprocess module in python. You can start another process using it, manipulate its streams and get the return code.

    0 讨论(0)
提交回复
热议问题