Python 操作系统故障

标签 python terminal os.system

我正在使用 pythonqt 设计一个界面,当我尝试使用 os.system 调用我的程序时,界面卡住了。

 def pairClicked(self,exp1,exp2):
      os.system("""cd kat
                   ./run -v pair""") #in the terminal i used to call my python interface, it runs this commands
      os.system(exp1+" "+expr2) #but here nothing happens

一旦我终止程序,终端就会说(在 exp1=t1exp2=t2 的情况下):

sh 1: t1 not found
sh 2: t2 not found

关于我做错了什么的想法/建议? 请注意,这是我第一次做这种事情。

编辑:

我已经编辑并使用了这段代码

 p=subprocess.Popen(['cd','kat','./run', '-pair', str(test.__len__()),expr1Text,expr2Text],stdout=subprocess.PIPE,shell=True)
 out= p.communicate()
 print(out)

但它正在返回 ('',None)。 我认为问题是我正在使用像 cd kat ./run -pair *len* expr1 expr2 这样的命令而不是:

cd kat
./run -pair *len*
expr1
expr2

如何使用子流程来换行?

最佳答案

听起来 ./run 正在阻塞。

您可能需要生成一个异步子进程或可能使用另一个线程,以便您的 GUI 可以在 ./run 运行时继续工作。

关于Python 操作系统故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270358/

相关文章:

python - 从脚本设置 Scrapy start_urls

python - 在使用此多对多关系之前,"<Story: title>"需要为字段 "id"提供一个值

python - 尝试将模型加载到另一个平台时 Keras ValueError : Unknown layer:name,

python - 在具有类的列表上使用 python Sorted 函数

python - 从 python 脚本启动时等待算盘作业完成

python os.system 似乎无缘无故挂起

bash - 如何为终端制作动画 bash shell 提示符?

terminal - 如何将 zsh 更新到最新版本?

html - 彩色 Git 差异到 HTML

Python3 : os. 系统不重定向标准输出