【问题标题】:Run php command with Boost::Process使用 Boost::Process 运行 php 命令
【发布时间】:2012-10-30 02:00:11
【问题描述】:

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

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();

在标准输出没有信息,但在标准错误我得到:

“boost::process::detail::posix_start: execve(2) failed: Permission denied”

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

有什么解决办法吗?

谢谢..

【问题讨论】:

  • 在 boost 中也获得权限(不仅在终端中),你应该没问题。
  • 如何“在 boost 中获取权限”?我尝试使用 sudo 从终端运行我的应用程序,但没有帮助...
  • 它很可能在不同的用户下运行。更改用户或使该用户也允许执行脚本。你在开发unixoid系统吗?
  • 我对 boost 没有(零)经验,但这听起来像是与文件系统中的 ACL 冲突。检查您要执行的文件的权限(php)。
  • 谢谢,你给了我正确的方向!我去 /usr/bin/ 检查权限并看到具有相同权限的 php5 命令(php 是指向 php5 的链接)。我不明白为什么,但是当我将命令替换为 php5 时,之前的错误被“没有这样的文件或目录”替换,当我给出完整路径时,它工作正常:exec =“/usr/bin/php5” ; args.clear(); args.push_back("php5");

标签: php boost process stdout permission-denied


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2018-08-25
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多