execl php - help please

hi, I'm new to linux, and I need some help please.
I'm using Ubuntu OS, and Eclipse CDT.
I'm trying to get the output of php program to my c++ program, using fork() and dup2().
on shell I wrote "php myscript.php" and got the output just fine, but when in c++
I tried
execl("usr/bin/php", "php", "home/geiger/workspace/SemiServer/server_content/myscript.php", NULL);
and it didn't work (there was no output and the process kept running, which I read happens when execl() runs into error).
I tried different versions of this function, like losing the "php" string and/or drop "home/geiger/" from the path, to no better results.
I would love it if anyone can point out the problem and a way to resolve it.
Thanks!
well, I'm still lost about the execl(), but I managed to override the problem by using system:
1
2
3
4
system("php myscript.php");
string executeKill = "kill -9 ";
string executeKill += my_itoa(pid);
system(executeKill.c_str());

but I would be grateful if someone can help with execl();
Why don't you write like this ?
execl("/usr/bin/php", "php", "/home/geiger/workspace/SemiServer/server_content/myscript.php", NULL);
If that fixes the problem I have to kind of laugh because it is things like that that have programmers pounding their heads against their desks - the problem is generally easier to see but we just never seem to look for it in that manner.
closed account (S6k9GNh0)
Usually, when I'm asked this question, I have to question why they're calling a PHP script from C++ in the first place. Is it to test a script? What possible advantage does calling a PHP script from C++ give exactly (outside of an actual webserver, in which case, lousy methods such as using system() is probably not the most effecient method to go about it).
Last edited on
A reason I can think of is sometimes we want to "interface" with a commercial third party software which do no expose any API. So we can only use input/output to "simulate talking" to those software as simple input/output are the most basic mechanism most commercial third party software supports isn't it ?
Last edited on
Topic archived. No new replies allowed.