首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将命令从python代码重定向到gnome-terminal

将命令从python代码重定向到gnome-terminal
EN

Stack Overflow用户
提问于 2019-02-03 10:56:52
回答 1查看 266关注 0票数 1

我有我的代码,其中包括几行:

代码语言:javascript
复制
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“,但它不起作用。有没有办法做到这一点?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-02-03 15:51:21

可以使用bash output.text作为命令参数,就像这样的'--command="bash output.text"'。注意,参数两边的引号是必需的。

代码语言:javascript
复制
subprocess.Popen(["gnome-terminal", "--working-directory=/home/huma/G-str/kaldi-gstreamer-server", '--command="bash output.text"'])

如果output.text不在设置的工作目录中,则必须提供完整路径。

可以用支持相同预期命令语言的任何其他外壳程序替换bash

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54499570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档