小编Gab*_*ira的帖子

Python:在执行之前检查shell命令是否存在

我正在尝试找到一种方法来在执行之前检查 shell 命令是否存在。

例如,我将执行命令 ack-grep。所以,我正在尝试这样做:

导入子流程
from subprocess import PIPE

cmd_grep = subprocess.Popen(["ack-grep", "--no-color", "--max-count=1", "--no-group", "def run_main", “../cgedit/”],stdout=PIPE,stderr=PIPE)

比,如果我执行

cmd_grep.stderr.read()

我收到像输出一样的“”。但我的路径上没有 ack-grep 命令。那么,为什么 Popen 没有将错误消息放在我的 .stderr 变量上?

另外,有没有更简单的方法来完成我想做的事情?

shell python process

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

process ×1

python ×1

shell ×1