[英]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.