latexmk
我正在尝试通过 PHP shell 执行命令函数生成凭证。我尝试了所有替代方案,但exec(), shell_exec(), passthru(), popen()
都没有成功。为了了解错误,我使用了$latexmk = passthru("latexmk -pdfxe -diagnostics $rec_fil");
以下日志:
当我怀疑这是一个user
相关问题时,我从 PHP 交互中运行了脚本并生成了所需的 pdf 输出。
我也尝试过该-f
选项latexmk
,但没有成功。
对于上述错误,我仅获取了aux
和fdb_latexmk
文件,而没有像我这样的新手能够了解是否存在问题的信息:
aux 文件内容:
\relax
\gdef \@abspage@last{1}
fdb_latexmk 文件内容:
# Fdb version 3
["xdvipdfmx"] 0 "001140.xdv" "001140.pdf" "001140" 0
"001140.xdv" 0 -1 0 "xelatex"
(generated)
"001140.pdf"
["xelatex"] 1637578209 "001140.tex" "001140.xdv" "001140" 1637578209
(generated)
"001140.xdv"
"001140.log"
将 STDOUT/STDERR 重定向到日志文件后,内容如下:
Set environment variable BIBINPUTS='.:'
Set environment variable TEXINPUTS='.:'
Given='001140.tex', tex='001140.tex', base='001140', ext= .tex, source=''
Rule classification:
Requested rules:
xdvipdfmx
No pre-primaries
Primaries:
xelatex
Post-primaries:
xdvipdfmx
No inner-level one_time rules, as expected
No outer-level one_time rules
Latexmk: Rules after start up for '001140.tex'
===Rules:
[dvifilter]: 'external' '' 'do_viewfile' 2 '001140.dvi' '001140.dviF' '001140' 0 0
'001140.dvi': 0 -1 0 'latex'
[dvips]: 'external' 'dvips %O -o %D %S' 'do_viewfile' 2 '001140.dvi' '001140.ps' '001140'
0 0
'001140.dvi': 0 -1 0 'latex'
[latex]: 'primary' 'latex -recorder %O %S' '' 1 '001140.tex' '001140.dvi' '001140' 0 0
'001140.tex': 0 -1 0 ''
[print]: 'external' 'NONE $lpr_pdf variable is not configured to allow printing of pdf files %O %S' 'if_source' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[psfilter]: 'external' '' 'do_viewfile' 2 '001140.ps' '001140.psF' '001140' 0 0
'001140.ps': 0 -1 0 'dvips'
[update_view]: 'external' '' 'do_update_view 1 1 0 1' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[view]: 'external' 'start start acroread %O %S' 'if_source' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[xdvipdfmx]: 'external' 'xdvipdfmx -E -o %D %O %S' 'do_viewfile' 2 '001140.xdv' '001140.pdf' '001140' 0 0
'001140.xdv': 0 -1 0 'xelatex'
[xelatex]: 'primary' 'xelatex -no-pdf -recorder %O %S' '' 1 '001140.tex' '001140.xdv' '001140' 0 0
'001140.tex': 0 -1 0 ''
Rule classification:
Requested rules:
xdvipdfmx
No pre-primaries
Primaries:
xelatex
Post-primaries:
xdvipdfmx
No inner-level one_time rules, as expected
No outer-level one_time rules
Rule classification:
Requested rules:
xdvipdfmx
No pre-primaries
Primaries:
xelatex
Post-primaries:
xdvipdfmx
No inner-level one_time rules, as expected
No outer-level one_time rules
Latexmk: Rules after initialization
===Rules:
[dvifilter]: 'external' '' 'do_viewfile' 2 '001140.dvi' '001140.dviF' '001140' 0 0
'001140.dvi': 0 -1 0 'latex'
[dvips]: 'external' 'dvips %O -o %D %S' 'do_viewfile' 2 '001140.dvi' '001140.ps' '001140' 0 0
'001140.dvi': 0 -1 0 'latex'
[latex]: 'primary' 'latex -recorder %O %S' '' 1 '001140.tex' '001140.dvi' '001140' 1 0
'001140.aux': 1637583680 32 3985256e7290058c681f74d7a3565a19 ''
'001140.tex': 0 -1 0 ''
[print]: 'external' 'NONE $lpr_pdf variable is not configured to allow printing of pdf files %O %S' 'if_source' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[psfilter]: 'external' '' 'do_viewfile' 2 '001140.ps' '001140.psF' '001140' 0 0
'001140.ps': 0 -1 0 'dvips'
[update_view]: 'external' '' 'do_update_view 1 1 0 1' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[view]: 'external' 'start start acroread %O %S' 'if_source' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[xdvipdfmx]: 'external' 'xdvipdfmx -E -o %D %O %S' 'do_viewfile' 2 '001140.xdv' '001140.pdf' '001140' 0 0
'001140.xdv': 0 -1 0 'xelatex'
[xelatex]: 'primary' 'xelatex -no-pdf -recorder %O %S' '' 1 '001140.tex' '001140.xdv' '001140' 1 0
'001140.aux': 1637583680 32 3985256e7290058c681f74d7a3565a19 ''
'001140.tex': 0 -1 0 ''
Rule classification:
Requested rules:
xdvipdfmx
No pre-primaries
Primaries:
xelatex
Post-primaries:
xdvipdfmx
No inner-level one_time rules, as expected
No outer-level one_time rules
Make: doing pre_primary and primary...
Make1 xelatex
remake
Latexmk: applying rule 'xelatex'...
No new source files for rule 'xelatex':
Removing no-longer-needed dependent '001140.aux' from rule 'xelatex'
Removing no-longer-needed dependent '001140.tex' from rule 'xelatex'
Latexmk: Rules after run:
===Rules:
[dvifilter]: 'external' '' 'do_viewfile' 2 '001140.dvi' '001140.dviF' '001140' 0 0
'001140.dvi': 0 -1 0 'latex'
[dvips]: 'external' 'dvips %O -o %D %S' 'do_viewfile' 2 '001140.dvi' '001140.ps' '001140' 0 0
'001140.dvi': 0 -1 0 'latex'
[latex]: 'primary' 'latex -recorder %O %S' '' 1 '001140.tex' '001140.dvi' '001140' 1 0
'001140.aux': 1637583680 32 3985256e7290058c681f74d7a3565a19 ''
'001140.tex': 0 -1 0 ''
[print]: 'external' 'NONE $lpr_pdf variable is not configured to allow printing of pdf files %O %S' 'if_source' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[psfilter]: 'external' '' 'do_viewfile' 2 '001140.ps' '001140.psF' '001140' 0 0
'001140.ps': 0 -1 0 'dvips'
[update_view]: 'external' '' 'do_update_view 1 1 0 1' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[view]: 'external' 'start start acroread %O %S' 'if_source' 2 '001140.pdf' '' '' 0 0
'001140.pdf': 0 -1 0 'xdvipdfmx'
[xdvipdfmx]: 'external' 'xdvipdfmx -E -o %D %O %S' 'do_viewfile' 2 '001140.xdv' '001140.pdf' '001140' 0 0
'001140.xdv': 0 -1 0 'xelatex'
[xelatex]: 'primary' 'xelatex -no-pdf -recorder %O %S' '' 1 '001140.tex' '001140.xdv' '001140' 0 0
Rule classification:
Requested rules:
xdvipdfmx
No pre-primaries
Primaries:
xelatex
Post-primaries:
xdvipdfmx
No inner-level one_time rules, as expected
No outer-level one_time rules
Latexmk: Errors, so I did not complete making targets
显然,latexmk
或者子级已删除aux
和tex
文件,因为从服务器运行时编译不再需要依赖它们,即 PHP。
这是我在日志中注意到的唯一的事情。
我该如何解决这个问题?
答案1
这是与 PATH 设置相关的问题。
我不确定这是否是 Scriptcase 中使用的 PHP 7.3 的一个非常特殊的情况,或者它是一个与 PHP 相关的一般问题。
虽然latexmk
确实执行并生成了aux
文件fdb_latex
。出于某些我不知道的原因,由于 PATH 设置不明确,它无法继续编译;请阅读以下段落。
我确实将编译传递给了一个sh
脚本,其中 PATH 设置在脚本的顶部,然后在使用所需选项/usr/local/bin:/usr/bin:/bin
调用之前进行了一些简单的 shell 处理latexmk
。根据 PHP 要求,STDOUT 和 STDERR 必须重定向。如果不定义 PATH,编译将失败。
PHP调用代码:
$tempdir = exec('mktemp -dt "latex.XXXX"');
$texfile = "$tempdir/001140.tex";
$stdoe = "$tempdir/stdoe.log";
$cmd = "$tempdir/latexmkit.sh";
exec("$cmd -t $texfile -l $stdoe");
剧本:
#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
while getopts t:l: flag; do
case "$flag" in
t) texfile=${OPTARG} ;;
l) oelog=${OPTARG} ;;
esac
done
latexmk -pdfxe -cd $texfile >>$oelog 2>&1
我不是一名 shell 程序员,请有人改进上述内容,使其更安全、更适合一般使用。