【发布时间】:2016-01-15 08:34:06
【问题描述】:
我正在将我当前的网站从 Red Hat 共享服务器转移到 Amazon AWS。当我移动我的工作代码时,我开始在我的 popen 调用中收到一个错误。
错误是:sh: 1: <command>: not found
我在 5 年前发现了一个类似的问题,但从来没有真正好的答案。 popen fails with "sh: <command>: not found"
我在我的 ubuntu 14.04 笔记本电脑上使用 XAMPP 作为本地测试平台,问题没有出现,但它出现在我的 AWS 实例上。在实例上使用带有 php5 和 apache2 的 ubuntu 14.04lts。
我怀疑这可能是 PHP 设置或路径问题,但我尝试的一切都失败了,有什么建议吗?
output = shell_exec('echo abc'); 工作正常。
这里有更多信息:我的代码:
if (file_exists(SitePATH."/solver/dkcube")){
//echo "Executable is there <br />";
error_reporting(E_ALL);
$handle = popen("$runvariable 2>&1","r");
echo "Line 1: '$handle'; ".gettype($handle). "<br />";
$contents = stream_get_contents($handle);
echo "Line 2: $contents"; pclose($handle);
runvariable 基本上是来自 file_exists 的 dkcube,其中包含一些传递变量。第 2 行的回声是
'第 2 行:sh:1:/var/www/html/solver/dkcube:未找到'
希望这可以为您提供更多信息。
我尝试了sudo -H -u php_user sh -c 'content of runvariable here',它返回了同样的错误:sh: 1: /var/www/html/solver/dkcube: not found
【问题讨论】:
-
“我尝试的一切都失败了” 你到底尝试了什么?它究竟是如何失败的?例如,
$output = shell_exec('echo abc');有效吗? -
如果你手动运行
sudo -H -u php_user sh -c 'content of runvariable here'会发生什么?
标签: php amazon-web-services ubuntu-14.04 popen