Run php command with Boost :: Process

I am trying to run a PHP script and get the output from stdout, the code is as follows:

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

There is no information in stdout, but in stderr I get:

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

And when I run the exact same command in the terminal, it works great!

Any solutions?

Thanks..

+4
source share
1 answer

Thanks @hakre, you gave me the right direction!

I went to / usr / bin / to check the permission and saw the php5 command with the same permissions as php (php is a link to php5).

I don’t understand why, but when I replaced the command with php5, the previous error was replaced by: "There is no such file or directory", and when I gave the full path, it works fine:

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

Source: https://habr.com/ru/post/1445116/


All Articles