【问题标题】:shell_exec not executing command in phpshell_exec 没有在 php 中执行命令
【发布时间】:2013-01-01 06:52:35
【问题描述】:

我正在尝试从 Windows 计算机运行此命令,但无法使其正常工作。当我将命令输入到命令提示符时,该命令可以正常工作,但在执行 PHP 脚本时却不行。

$command = '"C:\Program Files (x86)\WinSCP\winscp.exe" /console /command "open client" "cd /var/www/html/reports" "put C:\wamp\www\client\test.php" "exit"';
shell_exec($command);

【问题讨论】:

  • 您确定该方法不被禁止吗?你确定参数被正确转义了吗?
  • 您运行的是 Apache 还是您用作服务的任何服务器?如果你在 Windows 上,服务器是禁止与系统交互的,除非它有特殊权限或者作为正常进程打开。
  • 检查safe_modedisable_functionsphp.net/manual/en/ini.core.php 另外,从一个命令开始(例如运行 winscp)。
  • 我在应用程序的其他地方使用了 shell_exec,它工作正常。我检查了 disable_functions,那里没有列出任何内容。
  • 添加/log开关并检查日志。您还想使用winscp.com,而不是winscp.exe。见winscp.net/eng/docs/executables

标签: php winscp


【解决方案1】:

尝试使用exec(),它可以帮助您进行调试。

<?php
$command = '"C:\Program Files (x86)\WinSCP\winscp.exe" /console /command "open client" "cd /var/www/html/reports" "put C:\wamp\www\client\test.php" "exit"';
$cmd = exec($command, $arr, $opt);

// Output info run from the command:
var_dump($cmd, $arr, $opt);

【讨论】:

  • 我从这里得到了输出:string(0) "" array(0) { } int(1)
  • 看起来你运行了多个命令,你需要将它们分开,我不记得怎么做了,但我认为是&amp;命令:superuser.com/questions/62850/…
猜你喜欢
  • 2018-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-15
  • 1970-01-01
  • 2014-10-01
  • 2016-03-01
  • 1970-01-01
相关资源
最近更新 更多