我有我的代码,其中包括几行:
print("python kaldigstserver client.py -r 32000 ",self.filename,file=open("output.txt", "a"))
with open('output.txt') as my_file:
file_text = my_file.read()
print(file_text)
subprocess.Popen(args=["gnome-terminal", "--working-directory=/home/huma/G-str/kaldi-gstreamer-server"])这会在我执行python程序时打开一个终端......但是我想将命令从文本文件重定向到终端...即output.txt。并自动执行它。
我不知道该怎么做。我试过使用“--command”和"--execute“,但它不起作用。有没有办法做到这一点?
提前谢谢。
发布于 2019-02-03 15:51:21
可以使用bash output.text作为命令参数,就像这样的'--command="bash output.text"'。注意,参数两边的引号是必需的。
subprocess.Popen(["gnome-terminal", "--working-directory=/home/huma/G-str/kaldi-gstreamer-server", '--command="bash output.text"'])如果output.text不在设置的工作目录中,则必须提供完整路径。
可以用支持相同预期命令语言的任何其他外壳程序替换bash。
https://stackoverflow.com/questions/54499570
复制相似问题