【发布时间】:2018-07-12 18:18:11
【问题描述】:
app.py
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
command = /some/path/to/command
command = which(command)
if command is not None:
print "command exists and is exectuable"
child = subprocess.Popen(command)
输出:
command exists and is exectuable
[Errno 2] No such file or directory
当它在 docker 中运行时,即使它可以找到可执行文件,当它通过子进程运行时,它会抛出“没有这样的文件”错误
当它在容器外运行时,我看不到这种行为
当命令通过子进程运行时,关于这里发生了什么的任何建议?当我添加 shell=True 时,它仍然找不到它
【问题讨论】:
-
你的镜像是在 Ubuntu 上构建的吗?
-
@aerokite centos
-
ls -la /some/path/to/command? -
我以前见过这个问题。可能是您没有运行该命令的权限,或者该命令不可执行。
-
但是 which() 不能确保它是可执行的并且我可以运行它吗?现在我得到 /bin/sh: 1: ls: not found