【问题标题】:Hide output from proc_open command隐藏 proc_open 命令的输出
【发布时间】:2019-09-26 10:18:27
【问题描述】:

我有一个问题。也许这是一个初学者,但实际上我找不到解决我的问题的方法,而且我以前没有使用过这个命令。也许有人可以给我一个提示。

我正在使用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 文件不再生成。 我检查了抑制命令窗口输出的解决方案。我只找到了&gt; /dev/null,但这我也不能工作。

有没有人为我的问题提供解决方案或提示? 提前谢谢了! 如果缺少任何信息,请告诉我。到时候我会更新原帖。

【问题讨论】:

    标签: php windows process console


    【解决方案1】:

    我找到了答案。我可以通过简单地将&gt;nul 添加到命令中来抑制console 输出。所以这是我的解决方案:

    $process = proc_open('"' .$this->execute .'" >nul', $descriptorspec, $pipes, $cwd, $env);
    

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 2022-08-03
      • 2013-08-06
      • 2016-09-06
      • 1970-01-01
      相关资源
      最近更新 更多