【问题标题】:executing a Windows command line program with system call in PHP在 PHP 中使用系统调用执行 Windows 命令行程序
【发布时间】:2011-07-10 19:32:31
【问题描述】:

我正在尝试使用 php 文件中的系统调用来执行程序,如下所示:

$newname = 'C:\Users\Jack\Desktop\upload\test.ppt' ;
$program = '"C:\Program Files (x86)\Softinterface, Inc\Convert PowerPoint\ConvertPPT"';
$input = ' /S "'. $newname .'"' 
$destination = ' /T "C:\Users\Jack\Desktop\upload\\"';
$switch = ' /C 18';
$command = $program . $input . $destination . $switch;
system($command);

由于某种原因,程序进入了一个无限循环(浏览器永远不会停止加载)。我已经手动尝试了该命令,它运行良好(大约需要 2 秒才能完成),但是使用 php 文件执行它时不起作用。

【问题讨论】:

  • 您是否尝试过在系统调用之前回显$command 以确保正确写入?
  • @Kevin $command 是准确的
  • 嗯。那时不确定。你确定你真的在运行一个程序吗? '"C:\Program Files (x86)\Softinterface, Inc\Convert PowerPoint\ConvertPPT" 看起来不像你(你没有执行 Windows 二进制文件)。我希望你在最后有 someprogram.exe 之类的。
  • @Kevin,我添加了 .exe 扩展名,仍然进入无限循环

标签: php windows command-line system call


【解决方案1】:

使用反引号(`) 符号环绕您要运行的命令。

【讨论】:

  • exec、单引号、字符串连接都不需要。纯粹是backtick $command backtick
猜你喜欢
  • 2010-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-16
相关资源
最近更新 更多