使用 shell 脚本执行 java saxon 转换来创建文件

Use shell script to execute java saxon transform to create file

我一直在尝试使用 PHP 执行 shell 脚本 (.sh) 并使用 Java saxon.transform 创建文件。当我 运行 PHP 文件时,它没有显示任何错误,但文件没有被创建。

script.sh是可执行的(chmod +x),jar路径是预定义的。

script.sh

echo "Running step 01."
java net.sf.saxon.Transform -o:review.html -s:merged.html -xsl:xsls/01-simplify.xsl --suppressXsltNamespaceCheck:on;

if [ -f "review.html" ]
then
    echo "Review.html file successfully generated."
    echo "Done"
else
    echo "Something went wrong."
    echo "Check the <code>merged.html</code> file."
fi

php

echo shell_exec('./script.sh');

结果

Something went wrong.
Check the merged.html file.

相同的 java 命令在从命令行执行时按预期工作。它只是在网络上不起作用。

我在 Ubuntu 16.04,PHP7.

如有任何建议,我们将不胜感激。

谢谢。

如果您检查 error.log 文件,它应该会为您提供有关问题所在的更多详细信息。使用命令:

tail /var/log/apache2/error.log -n 100

或类似

我在 php 环境中尝试了 运行 类似的 shell 脚本。我收到以下错误:

Error on line 7 of test.xsl: Failed to create output file file:/var/www/html/samples/review.html: Permission denied in built-in template rule Failed to create output file file:/var/www/html/samples/review.html

这可能是您在创建输出文件时遇到的权限问题。