gpt4 book ai didi

PHP - 无法执行 C++ 二进制文件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:57:57 25 4
gpt4 key购买 nike

我正在尝试从 PHP 执行我使用 cmake 和 make 命令生成的 C++ 二进制文件。如果我尝试从终端执行相同的命令,一切正常,但从 php 似乎没有任何反应。我检查了 safe_mode,它关闭了。我已经使用 chmod 授予了所有可执行权限。我试过将东西放在同一个文件夹,不同的文件夹中。事实上,我已经尝试了我能想到的所有可能的解决方案,但我仍然无法执行这些二进制文件。知道为什么我不能这样做吗?

非常感谢任何帮助。

提前致谢。

我使用的程序:-

if($dir !== FALSE) {
$command = "./segmentation.sh $dir->dirname >> $dir->dirname/log";
$output = $this->terminal($command);
echo $output['output'];
}

终端功能

public function terminal($command)
{
if(function_exists('system'))
{
ob_start();
system($command , $return_var);
$output = ob_get_contents();
ob_end_clean();
}
else if(function_exists('passthru'))
{
ob_start();
passthru($command , $return_var);
$output = ob_get_contents();
ob_end_clean();
}
else if(function_exists('exec'))
{
exec($command , $output , $return_var);
$output = implode("n" , $output);
}
else if(function_exists('shell_exec'))
{
$output = shell_exec($command) ;
}
else
{
$output = 'Command execution not possible on this system';
$return_var = 1;
}
return array('output' => $output , 'status' => $return_var);
}

我的 shell 脚本有一个正常的二进制调用

/path/to/folder/binary_file $args

我从我的 shell 脚本中尝试了 echo、ls、mkdir cmd,它运行完美,只是这些二进制文件没有被执行。

最佳答案

看起来您的工作目录可能与您想象的不同。

试试这个:

$path = realpath(dirname(__FILE__) );

$cmd = $path . $command;

并尝试执行该命令(假设 c++ 文件与您正在运行的 php 文件位于同一目录中。

关于PHP - 无法执行 C++ 二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15237410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com