抱歉,我真的不能解释得更好了。我在学习shell编程。
我试图检测作曲家是否有一个名为“post”的脚本。要做到这一点,人们可以调用composer run-script --list (文档)。因此,我在条件内将该命令传输到grep -q。
当我在Docker层(发行版基于Debian)中运行这个程序时,只有在条件内调用composer run-script --list时才会得到一个错误:
RUN set -eux; \
if [ -f composer.json ]; then \
composer dump-autoload --no-dev --classmap-authoritative; \
# This is working fine, a list is returned (see log)
composer run-script --list; \
# This gives me an error (Unable to write output)
if composer run-script --list | grep -q post-install-cmd; then \
echo "Script was found!"; \
fi; \
fi日志:
#41 [myproject php_prod 9/10] RUN set -eux; if [ -f composer.json ]; then composer dump-autoload --no-dev --classmap-authoritative; composer run-script --list; if composer run-script --list | grep -q post-install-cmd; then echo "Script was found!"; fi; fi
#41 0.441 + [ -f composer.json ]
#41 0.445 + composer dump-autoload --no-dev --classmap-authoritative
#41 0.835 Generating optimized autoload files (authoritative)
#41 0.878 Generated optimized autoload files (authoritative) containing 40 classes
#41 0.892 + composer run-script --list
#41 1.164 scripts:
#41 1.168 auto-scripts Runs the auto-scripts script as defined in composer.json.
#41 1.169 post-install-cmd
#41 1.169 post-update-cmd
#41 1.183 + grep -q post-install-cmd
#41 1.188 + composer run-script --list
#41 1.468 scripts:
#41 1.471
#41 1.479
#41 1.480 [Symfony\Component\Console\Exception\RuntimeException]
#41 1.481 Unable to write output.
#41 1.481
#41 1.481
#41 1.482 run-script [--timeout TIMEOUT] [--dev] [--no-dev] [-l|--list] [--] [<script>] [<args>]...
#41 1.482
#41 1.495 + echo Script was found!
#41 1.497 Script was found!
#41 DONE 1.6s发布于 2023-05-09 20:53:42
通过将--no-ansi选项添加到composer运行脚本--list命令中,可以尝试禁用ANSI转义代码用于输出格式设置。这可以偶尔修复终端环境中不支持它们的输出相关问题。
RUN set -eux; \
if [ -f composer.json ]; then \
composer dump-autoload --no-dev --classmap-authoritative; \
composer run-script --list; \
if composer run-script --list --no-ansi | grep -q post-install-cmd; then \
echo "Script was found!"; \
fi; \
fi或者另一种选择:
docker run -t my_imagehttps://serverfault.com/questions/1130776
复制相似问题