#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    hi,
    i have a small C program as below:

    main()
    {
    char name[10];
    scanf("%s",name);
    printf("Your name is : %s",name);
    }

    i'd like to interface with the C prog using PHP, and i've done it as follows:

    $command=exec("ctest < query.dat > query.res ");

    where the file 'query.dat' contains my name, and i'd like the resulting "Your name is : NAME" to be redirected to the file 'query.res'.

    Now the porblem is that if i execute the PHP code on the linux prompt then everything is fine. but if i try to invoke the PHP file thro the browser i dont get the proper output. in fact a non-empty 'query.res' becomes empty after the PHP file is invoked by a browser.

    i'm unable to identify the problem clearly. can u please tell me what is wrong, or show other alternatives to accomplish the same.
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,643
    Rep Power
    4492
    Could it be a permissions problem? PHP runs as nobody or www, what are you running as when you execute it on the command line. You might have to change the permissions on each file....

    My $0.02

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    no, it isn't the problem with permissions. i have 777 permission for both the 'query.dat' and 'query.res'.

    as i've told, the PHP code runs well on the prompt and 'query.res' then contains "your name is : NAME". but if i invoke the PHP code thro the browser and then check 'query.res' i find that it is EMPTY (which had contents before the invoke). the contents now have disappeared. the fact that 'query.res' have been written suggests that there is no probs with the permission. it is something which i cant figure out.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    the point is that i'm interested in the output of the C program. if there is another way of getting that data without the use of files would be even better. is there absolutely no way of getting the information, either by files, pipes, variables or redirections?
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,643
    Rep Power
    4492
    Can't you just do

    $results = exec("ctest");

    Anything normally printed to the screen will be assigned to the $results variable...

    ---John Holmes...
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    I tried John. i modified the exec() to:

    $return=exec("ctest < query.dat");
    echo "$return";

    but still the same problem. the resulting "your name is: NAME" appears while running from the prompt, but nothing when invoked from the browser.
    my situation hasn't changed much.
  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    3
    Rep Power
    0
    How about

    exec("./ctest < query.dat", $result_lines, $result_code);

    and looking at the values of the $result_lines array?

    (see http://www.php.net/manual/function.exec.php)
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    thanx cokeman. it worked the way i wanted.

    but originally i was using the C program as a dummy to test the interaction with an external program which runs in a similar manner. i get the program running using:

    $command=exec("mgquery title < query.dat", $outputmg,$res);

    Here i give my name in 'query.dat' and expect relevant information to be given to me. THIS works well on the prompt, but NOT when invoked by the browser. and i cannot run the program using "./mgquery title". it says
    "sh: ./mgquery: no such file or directory"
    And even this error message is not available to the browser. so cokeman's method solved the dummy problem but not the actual problem.

    The details of the program that i'm trying to run can be found at (http://www.mds.rmit.edu.au/mg/) which is actually an information retreival system.

    can u please help solve the actual problem. i'm even ready to interact personally by mail.
  16. #9
  17. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    3
    Rep Power
    0
    It sounds like it's a path problem. You could try prepending the entire path for the mgquery program, instead of the ./

    I mean something like exec("/usr/local/somepath/mgquery", $msg, $res) instead of exec("./mgquery", $msg, $res).

    Also, I haven't looked at that MG page too closely, but if 'title' is a file, you might want to specify the path for that, and also for your query.dat file.
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    hey cokeman, U should've seen the earlier messages. i'm able to run the code on the prompt, but not thro the browser. i've specified the path to the file in a variable and used exec() with the variable as the parameter. i've also tried specifying the full path in the exec() function itself. but i'm still encountering the SAME PROBLEM!!! i'm ABLE to get the output on the prompt, but NOT thro the browser.

    the program mgquery exists in the path. it cannot be executed using ./mgquery

    my position ahs not changed much.

IMN logo majestic logo threadwatch logo seochat tools logo