【问题标题】:impossibility to use PHP exec() with a function in windows7无法在 windows7 中将 PHP exec() 与函数一起使用
【发布时间】:2014-01-29 16:19:19
【问题描述】:

我提出了我的问题:我使用 wampserver 2.4 创建一个无法创建文件 .tex 的本地站点。接下来我想用 MiKTeX 编译这个文件(命名为devoir.tex),所以latex.exebin 目录中。但是,使用exec(),我无法创建.dvi 文件并且程序永远不会停止。我的不同代码示例:

  1. $path='C:\MiKTeK\miktex\bin\x64\latex.exe devoir.tex';

    exec($path);

  2. exec('start C:\MiKTeK\miktex\bin\x64\latex.exe devoir.tex');

  3. shell_exec('C:\MiKTeK\miktex\bin\x64\latex.exe devoir.tex ');

不要创建.dvi 文件。

十年前,我用easyphp做这个网站,还可以。但是现在,我不明白这个问题:句法问题?其他原因是windows7?

【问题讨论】:

  • (1) 各种exec 调用返回什么?
  • (2) devoir.tex 住在哪里?在大多数情况下,“当前目录”是主脚本的位置。如果您的文件名是相对的(即:如果它不以斜杠或 Windows 中的反斜杠开头),它通常应该是相对于该位置的。
  • cHao:我怎么知道 exec 调用的 return 是什么?他们从不停止。文件 devoir.tex 与我网站的 index.php 位于同一目录中。
  • 拨打phpinfo()看安全模式是否开启;如果是这样,您将无法运行 exec()shell_exec()。我相信它在 wampserver 中默认开启。
  • 当您从命令行运行程序时,准确输入您传递给*exec 的内容,它可以工作吗?

标签: php latex tex miktex


【解决方案1】:

在php.net评论sbourazanis上试试解决方案

/**
 * Fonction Exec marche mal sous Windows, donc il en faut une autre 
 * fr.php.net/manual/fr/function.exec.php#86438
 * @param string $cmd
 * @return boolean
 */
public function _exec($cmd) 
{ 
    $WshShell = new COM("WScript.Shell"); 
    $oExec = $WshShell->Run($cmd, 0, true); //0 pour avoir une fenêtre cachée
                                            //true pour attendre la fin de l'éxécution
                                            //cf. http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29

    return $oExec == 0 ? true : false; 
}

【讨论】:

    猜你喜欢
    • 2010-10-26
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 2018-05-08
    相关资源
    最近更新 更多