简体   繁体   English

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

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

app.py 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)

OUTPUT: 输出:

command exists and is exectuable
[Errno 2] No such file or directory

when this is run inside docker, even though it could find the executalbe, when it's run via subprocess, it is throwing the "no such file" error 当它在docker内部运行时,即使它可以找到executalbe,当它通过子进程运行时,它也会抛出“无此文件”错误

when this is run outside of container, i dont see this behavior 当它在容器外运行时,我看不到此行为

any advice on what's going on here when the command is run via subprocess? 通过子进程运行命令时,这里发生了什么建议? when I added shell=True, it still cant find it 当我添加shell = True时,它仍然找不到

I experienced this issue also. 我也遇到了这个问题。 I had script_1 with hashbang #!/usr/bin/env python3 which called Popen(['script_2']) which had hashbang #!/bin/env python3 . 我有script_1带有hashbang #!/usr/bin/env python3 Popen(['script_2']) ,它调用了具有hashbang #!/bin/env python3 Popen(['script_2']) Popen() was reporting [Errno 2] No such file or directory: '/path/to/script_2': '/path/to/script_2' , but actually the problem that /bin/env didn't exist. Popen()正在报告[Errno 2] No such file or directory: '/path/to/script_2': '/path/to/script_2' ,但实际上/bin/env不存在。 I corrected script_2's hashbang to use /usr/bin/env to fix the problem. 我更正了script_2的hashbang以使用/usr/bin/env来解决此问题。

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

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