Python子进程check_output FileNotFoundError: [Errno 2] 未找到该文件或目录

2024-06-01 12:46:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个小python脚本来构建和测试我的docker映像。脚本在本地运行良好,但在check_output期间远程失败。在

在构建.py在

    print(check_output(["which", "dgoss"]))
    result = str(check_output(["dgoss", "run", image_tag], cwd=image_path, stderr=subprocess.DEVNULL))

.gitlab公司-词yml在

^{pr2}$

输出

dgoss master has been installed to /usr/local/bin/dgoss
$ ls -la /usr/local/bin/ | grep goss
-rwxr-xr-x    1 root     root          3803 May 17 08:58 dgoss
-rwxr-xr-x    1 root     root       8524064 May 17 08:58 goss
$ which dgoss
/usr/local/bin/dgoss
$ python3 ./infrastructure/build.py
infrastructure/broker
b'/usr/local/bin/dgoss\n'
Traceback (most recent call last):
  File "./infrastructure/build.py", line 54, in <module>
    test()
  File "./infrastructure/build.py", line 42, in test
    result = str(check_output(["dgoss", "run", image_tag], cwd=image_path, stderr=subprocess.DEVNULL))
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 423, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dgoss': 'dgoss'

文件存在且可执行。为什么python抛出异常?在


Tags: inpyimageoutputbinlibusrlocal