简体   繁体   English

当cmd是文本变量时运行subprocess.call(cmd)

[英]Run subprocess.call(cmd) while the cmd is a text variable

In python, is it possible to run a shell command, while the command stored in variable as text ? 在python中,是否可以运行shell命令,而该命令以文本形式存储在变量中? for example: 例如:

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

this code doesn`t work! 此代码不起作用!

this is the right answer: 这是正确的答案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows cmd python subprocess.call - Windows cmd python subprocess.call 如何在不打开 CMD window 的情况下通过 subprocess.call() 运行 CMD 命令? - How to run CMD commands via subprocess.call() without opening CMD window? subprocess.call在Windows上使用cygwin而不是cmd - subprocess.call using cygwin instead of cmd on Windows 在python中的system(cmd)命令中形成subprocess.call()语句 - form a subprocess.call() statement from system(cmd) command in python os.system(cmd)和subprocess.call(cmd,shell = True)执行的命令与CMD.EXE不同 - os.system(cmd) and subprocess.call(cmd, shell=True) don't execute the same as CMD.EXE subprocess.call运行Mafft - subprocess.call to run mafft 在subprocess.call中使用变量 - Use a variable in subprocess.call ffmpeg comman可以使用subprocess.call()或os.system()在cmd中工作,但不能在Python中工作 - A ffmpeg comman canwork in cmd but not in Python using subprocess.call() or os.system() 使用python subprocess.call运行命令失败,但在键入cmd.exe时可以正常运行 - Running command with python subprocess.call fails but works correctly when typed into cmd.exe cmd执行但python os.popen和subprocess.call和subprocess.popen和os.system无法执行,为什么? - cmd executes but python os.popen and subprocess.call and subprocess.popen and os.system does not execute, why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM