【问题标题】:difference between terminal execution and popen终端执行和popen的区别
【发布时间】:2016-08-23 20:40:05
【问题描述】:

在我的 ubuntu 终端中键入命令会识别我命令中的参数 t

/home/daniel/Downloads/SALOME-7.6.0-UB14.04/salome start -t

在python中通过Popen启动同一个进程有什么区别?

command ='/home/daniel/Downloads/SALOME-7.6.0-UB14.04/salome'
commandargs= 'start -t'

import subprocess
subprocess.Popen([command, commandargs], shell=True).wait()

我的参数代表终端模式,但通过 python Popen 运行我的应用程序 (salome) 会打开 GUI。

【问题讨论】:

  • /home/daniel/Downloads/SALOME-7.6.0-UB14.04/salome start -t 中,“start”和“-t”是两个单独的参数,因此它们属于 args 列表中的两个不同列表项(在这种情况下使用 shell=True 也没有意义)
  • 像这样使用你的命令参数:commandargs= ['start', '-t']

标签: python python-2.7 terminal subprocess popen


【解决方案1】:

见:https://docs.python.org/3.5/library/subprocess.html#subprocess.Popen

args should be a sequence of program arguments or else a single string. 


另见:https://stackoverflow.com/a/11309864/2776376

subprocess.Popen([command, commandargs.split(' ')], shell=True).wait()

您也可以这样做,尽管不太推荐:

subprocess.Popen(command + commandargs, shell=True).wait()

应该做的伎俩

【讨论】:

  • subprocess.Popen((command+' '+ commandargs).split(' '), shell=True).wait() 是正确的,但我有同样的问题
猜你喜欢
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多