我有一个问题。也许这是一个初学者,但实际上我找不到解决我的问题的方法,而且我之前从未使用过此命令。也许有人可以给我提示。
我正在使用php
proc_open
命令运行pdflatex.exe
从tex
文件生成PDF文件。
代码如下:
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "D:/Freigabe/error.txt", "a")
);
$cwd = str_replace("\\", "/", __DIR__) .'/Tex/Working';
$env = null;
$this->execute = '"' .str_replace('/','\\',env('PDFLATEXENGINE', 'C:/Program Files (x86)/MiKTeX 2.9/miktex/bin/pdflatex.exe')) .'" -jobname="' .str_replace('.pdf','',$this->publicPdfFile) .'" -output-directory="' .str_replace("\\", "/", $this->pdfTargetPath) .'" "' .str_replace("\\", "/", str_replace(".tex","",$this->workingFilePath));
$process = proc_open('"' .$this->execute .'"', $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
fwrite($pipes[0], '<?php print_r($_ENV); ?>');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
一个命令示例是这个命令:
$this->execute = '"D:\Program Files\TeXLive\texlive\2019\bin\win32\pdflatex.exe" -jobname="Rechnung_000036-19" -output-directory="D:/Files/Company/Tool/app/Classes/Rechnung/LaTex/Output/" "D:/Files/Company/Tool/app/Classes/Rechnung/LaTex/Output/Rechnung_FUmtC1P7lknTzvDfstMM_000036-19"';
这很好用,但是命令本身在生成PDF文件时会产生一些输出。使用上面的代码,命令的输出将打印到我的网页上,如下所示:
我也知道,为什么要打印出来。只是因为此代码行:
fwrite($pipes[0], '<?php print_r($_ENV); ?>');
但是当我注释掉print_r()
命令时,不再生成PDF文件。
我检查了抑制命令窗口输出的解决方案。我只找到> /dev/null
,但是我也无法正常工作。
有人对我的问题有解决方案或提示吗? 提前谢谢了! 如果缺少任何信息,请告诉我。然后,我将更新原始帖子。
答案 0 :(得分:0)
我找到了答案。我可以通过简单地在命令中添加console
来抑制>nul
的输出。所以这是我的解决方案:
$process = proc_open('"' .$this->execute .'" >nul', $descriptorspec, $pipes, $cwd, $env);