我正在使用 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=t1
和 exp2=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/