gpt4 book ai didi

php - 使用 Boost::Process 运行 php 命令

转载 作者:可可西里 更新时间:2023-10-31 23:22:44 24 4
gpt4 key购买 nike

我尝试运行 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");

关于php - 使用 Boost::Process 运行 php 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13313334/

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