从运行Python中的bash脚本 [英] Running a bash script from Python
本文介绍了从运行Python中的bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要运行在Python bash脚本。我得到它的工作方式如下:
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")
这不正是我在做什么,但pretty太多的想法。这工作正常,新的终端窗口打开,我拿着它进行调试,但我的问题是我需要的python脚本继续运行,即使没有完成。什么办法可以做到这一点?
That isn't exactly what I am doing but pretty much the idea. That works fine, a new terminal window opens and I hold it for debugging purposes, but my problem is I need the python script to keep running even if that isn't finished. Any way I can do this?
推荐答案
我推荐你使用子
模块:的文档
I recommend you use subprocess
module: docs
您可以
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,:).
编辑拼写错误
这篇关于从运行Python中的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文