gpt4 book ai didi

python子进程 "no such file or directory"inside docker

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:27 25 4
gpt4 key购买 nike

应用.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 中运行时,即使它可以找到 executalbe,当它通过子进程运行时,它会抛出“没有这样的文件”错误

当它在容器外运行时,我看不到这种行为

关于通过子进程运行命令时这里发生了什么的任何建议?当我添加shell=True时,它仍然找不到它

最佳答案

我也遇到过这个问题。我有 script_1 和 hashbang #!/usr/bin/env python3 调用了 Popen(['script_2']) 有 hashbang #!/bin/env python3。 Popen() 报告 [Errno 2] No such file or directory: '/path/to/script_2': '/path/to/script_2',但实际上是 /bin 的问题/env 不存在。我将 script_2 的 hashbang 更正为使用 /usr/bin/env 来解决问题。

关于python子进程 "no such file or directory"inside docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48579428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com