November 14th, 2000, 07:29 AM
i have a small C program as below:
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.
November 14th, 2000, 07:49 AM
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....
November 14th, 2000, 08:55 AM
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.
November 15th, 2000, 05:31 AM
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?
November 15th, 2000, 06:39 AM
Can't you just do
$results = exec("ctest");
Anything normally printed to the screen will be assigned to the $results variable...
November 15th, 2000, 07:02 AM
I tried John. i modified the exec() to:
$return=exec("ctest < query.dat");
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.
November 15th, 2000, 01:33 PM
November 16th, 2000, 08:23 AM
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.
November 16th, 2000, 11:07 AM
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.
November 17th, 2000, 08:08 AM
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.