Python 2.7 subprocess returns 没有,确切的命令在控制台中有效
Python 2.7 subprocess returns nothing, exact command works in console
我正在尝试在 Python 脚本中执行 strings
命令。我让它工作了一段时间,但奇怪的是,当我再使用 subprocess.Popen
时,它 return 没有任何作用。
从终端调用
strings /path/to/.bashrc
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval `dircolors`
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
shopt -u -o history
在Python shell:
import subprocess
proc = subprocess.Popen(['strings', '/path/to/.bashrc'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = proc.communicate()
第二个return没什么。为什么?
The shell argument (which defaults to False) specifies whether to use the shell as the program to execute. If shell is True, it is recommended to pass args as a string rather than as a sequence.
尝试使用:
proc = subprocess.Popen("strings /path/to/file", ...)
我正在尝试在 Python 脚本中执行 strings
命令。我让它工作了一段时间,但奇怪的是,当我再使用 subprocess.Popen
时,它 return 没有任何作用。
从终端调用
strings /path/to/.bashrc
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval `dircolors`
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
shopt -u -o history
在Python shell:
import subprocess
proc = subprocess.Popen(['strings', '/path/to/.bashrc'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = proc.communicate()
第二个return没什么。为什么?
The shell argument (which defaults to False) specifies whether to use the shell as the program to execute. If shell is True, it is recommended to pass args as a string rather than as a sequence.
尝试使用:
proc = subprocess.Popen("strings /path/to/file", ...)