簡體   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