Python 在cmd为文本变量时运行subprocess.call(cmd)

Python 在cmd为文本变量时运行subprocess.call(cmd),python,unix,Python,Unix,在python中,当命令以文本形式存储在变量中时,是否可以运行shell命令? 例如: self.command_editor = QTextEditor() self.command_editor.append("echo command") cmd = str(self.command_editor.toPlainText()) call(cmd) 这个代码不起作用 这是正确的答案: self.command_editor = QTextEditor() self.

在python中,当命令以文本形式存储在变量中时,是否可以运行shell命令? 例如:

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

这个代码不起作用

这是正确的答案:

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