我的代码包含几行:
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”尝试过,但它不起作用。有什么办法可以做到吗????
提前致谢。
最佳答案
可以使用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
不在设置的工作目录中,则必须给出完整路径。
可以用支持相同预期命令语言的任何其他 shell 替换 bash
。
关于python - 将命令从 python 代码重定向到 gnome-terminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54499570/