繁体   English   中英

泊坞窗内的python子进程“无此文件或目录”

[英]python subprocess “no such file or directory” inside docker

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内部运行时,即使它可以找到executalbe,当它通过子进程运行时,它也会抛出“无此文件”错误

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM