#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Question Using execl() to run php in Linux


    Hi, my name is Geiger and I'm new to Linux. I'm using Ubuntu, and I'm programing with eclipse CDT.
    My goal is to execute a php file and read the output to my c++ program. To do so I thought I should use fork(), dup2() and execl.
    When in shell, the call "php myscript.php" worked 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 (the process wasn't terminated and I got no output).
    I tried different version of this call, like losing the "php" string and/or drop "home/geiger" from the path string, to no better result.
    I would be grateful if anyone could point out the problem and a way to solve it.
    Thanks in advance!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,446
    Rep Power
    1751
    I dodn't know C++ but should not the full paths start with a /, so:

    execl("/usr/bin/php", "php", "/home/geiger/workspace/SemiServer/server_content/myscript.php", NULL);
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0
    thanks very much, i can't try it right now but i'll check it out as soon as i can. o, and thanks again.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0
    worked perfectly! thanks
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,446
    Rep Power
    1751
    Glad to be of service!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo