我正在将我当前的网站从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行的回显是
&#39;第2行:sh:1:/ var / www / html / solver / dkcube:not found&#39;
希望能为您提供更多信息。
我尝试了sudo -H -u php_user sh -c 'content of runvariable here'
并返回了相同的错误:sh: 1: /var/www/html/solver/dkcube: not found
答案 0 :(得分:1)
感谢J.F塞巴斯蒂安的事实发现问题,他给了我解决问题所需的小窍门。使用他的sudo -H -u php_user sh -c 'content of runvariable here'
问题,我确定这是一个ubuntu问题而不是php问题。
我的问题的根本原因是我在64位操作系统上运行了32位可执行文件,并且没有为我的可执行文件安装正确的库。
首先,我必须将sh从短划线更改为bash,如下所示:source command not found in sh shell
然后我必须安装正确的库,如下所示:https://unix.stackexchange.com/questions/75054/ldd-tells-me-my-app-is-not-a-dynamic-executable