简体   繁体   English

Python子进程check_output FileNotFoundError:[Errno 2]没有这样的文件或目录

[英]Python subprocess check_output FileNotFoundError: [Errno 2] No such file or directory

I wrote a little python script to build and test my docker images of that project. 我写了一个小的python脚本来构建和测试该项目的docker镜像。 The script runs well locally, but fails remotely during check_output . 该脚本在本地运行良好,但在check_output期间远程失败。

build.py build.py

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

.gitlab-ci.yml .gitlab-ci.yml

    before_script:
      - curl -fsSL https://goss.rocks/install | sh
      - ls -la /usr/local/bin/ | grep goss
    script:
      - which dgoss
      - python3 ./infrastructure/build.py

Output 产量

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'

The file is present and executable. 该文件存在且可执行。 Why does python throw the exception? 为什么python会抛出异常?

Turns out dgoss is a bash wrapper around goss and alpine docker images ship without bash. 原来,dgoss是一个围绕高斯和高山码头图像的bash包装,没有bash。

before_script:
  - apk add curl python3 bash

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

相关问题 python子进程check_output - python subprocess check_output Python子进程没有属性“check_output” - Python subprocess has no attribute “check_output” Python 3.10 子进程错误:FileNotFoundError:[Errno 2] 没有这样的文件或目录:&#39;pkill&#39; - Python 3.10 subprocess error: FileNotFoundError: [Errno 2] No such file or directory: 'pkill' 子进程命令显示 FileNotFoundError: [Errno 2] No such file or directory - Subprocess command shows FileNotFoundError: [Errno 2] No such file or directory python:FileNotFoundError:[Errno 2]没有这样的文件或目录 - python: FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError:[错误2]没有这样的文件或目录 - Python FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录 [Python] - FileNotFoundError: [Errno 2] No such file or directory [Python] python check_output FileNotFoundError: [WinError 2] 系统找不到指定的文件 - python check_output FileNotFoundError: [WinError 2] The system cannot find the file specified Python 3-FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3 - FileNotFoundError: [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM