使用Boost :: Process运行php命令

我尝试运行PHP脚本并从stdout获取输出,代码如下所示:

using namespace boost::process;

std::string exec="php";
std::vector<std::string> args;

// I must to throw the exe by argument
args.push_back("php");
args.push_back("a.php");

context ctx;
ctx.stdout_behavior = capture_stream();
child c = launch(exec, args, ctx);

pistream &is = c.get_stdout();

stdout没有信息,但在stderr我得到:

“boost :: process :: detail :: posix_start:execve(2)失败:权限被拒绝”

当我在终端中运行完全相同的命令时,它工作正常!

有解决方案吗

谢谢..

解决方法:

谢谢@hakre,你给了我正确的方向!

我去/usr/bin /检查权限,看到php5命令与php具有相同的权限(php是php5的链接).

我不明白为什么,但是当我将命令替换为php5时,之前的错误被替换为:“没有这样的文件或目录”,当我给出完整路径时,它工作正常:

exec="/usr/bin/php5";
args.clear();
args.push_back("php5");

相关文章

文章浏览阅读8.4k次,点赞8次,收藏7次。SourceCodester Onl...
文章浏览阅读3.4k次,点赞46次,收藏51次。本文为大家介绍在...
文章浏览阅读1.1k次。- php是最优秀, 最原生的模板语言, 替代...
文章浏览阅读1.1k次,点赞18次,收藏15次。整理K8s网络相关笔...
文章浏览阅读1.2k次,点赞22次,收藏19次。此网络模型提供了...
文章浏览阅读1.1k次,点赞14次,收藏19次。当我们谈论网络安...