简体   繁体   中英

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)

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

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

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 . 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. I corrected script_2's hashbang to use /usr/bin/env to fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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