shlex.split在“ kill -9 $(pgrep Electron)”上失败

时间:2018-09-03 15:45:01

标签: python python-3.x

我想用命令关闭vscode:

In [8]: cmd = "kill -9 $(pgrep Electron)"
In [11]: subprocess.Popen(cmd, shell=True)
Out[11]: <subprocess.Popen at 0x10d1d0438>

它有效,但是当我尝试不带shell = True的替代品时

In [13]: cmd = "kill -9 $(pgrep Electron)"
In [14]: cmd = shlex.split(cmd)

In [15]: cmd
Out[15]: ['kill', '-9', '$(pgrep', 'Electron)']

In [16]: subprocess.Open(cmd)
AttributeError: module 'subprocess' has no attribute 'Open'

如何启用预期的工作?

0 个答案:

没有答案