2013-09-29 20 views
0

在Python中,是否可以運行shell命令,而命令是否以變量形式存儲爲文本? 例如:當cmd是文本變量時運行subprocess.call(cmd)

self.command_editor = QTextEditor() 
    self.command_editor.append("echo command") 
    cmd = str(self.command_editor.toPlainText()) 
    call(cmd) 

這個代碼不`噸的工作!

回答

1

這是一個正確的答案:

self.command_editor = QTextEditor() 
    self.command_editor.append("echo command") 
    cmd = str(self.command_editor.toPlainText()) 
    call(cmd, shell = True) #the mistake was here