Running a bash script from Python

前端 未结 1 1582
南笙
南笙 2021-01-19 16:39

I need to run a bash script from Python. I got it to work as follows:

import os
os.system(\"xterm -hold -e scipt.sh\")

That isn\'t exactly

相关标签:
1条回答
  • 2021-01-19 17:31

    I recommend you use subprocess module: docs

    And you can

    import subprocess
    
    cmd = "xterm -hold -e scipt.sh"
    # no block, it start a sub process.
    p = subprocess.Popen(cmd , shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    
    # and you can block util the cmd execute finish
    p.wait()
    # or stdout, stderr = p.communicate()
    

    For more info, read the docs,:).

    edited misspellings

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