|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with PHP calling C
Hi. I am trying to call a C program using PHP. I have the program running on a Linux Redhat 7.2. I am using PHP4.
My C program prints out a few welcome messages before it checks if the development board that I am using is connected to it. If I run the program using the console, the board is detected but when I tried to run it from my browser, the development board is NOT detected. I am using exec() to run my program. Could someone please advice? I am really new to this. Also, I need to pass and get some variables to/from the C program from my PHP file. Is it possible? Any help would be appericiated. Thanks in advanced. |
|
#2
|
||||
|
||||
|
Quote:
Could be one of 1000 possible reasons. - wrong path - exec() not allowed in your webserver config - chroot´d environment ... Quote:
for small variables, i would recommend the command line. call the C program like this: exec("mycprogram $name $name2 $name3"); and read the variables via your "**argv" parameter in the C program. For more complex situations, you need to get into IPC or sockets as both (PHP and C) do support them. the easiest of these mechanisms would imho be piping, i.e. popen() the C program instead of exec(), fwrite() to the pipe and make the C program read the variables from stdin.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
|||
|
|||
|
Hi. Thanks for the advice. But I still can't solve the problem. I think I may have been a bit brief in my previous posting. This is the situation. The C Program was previously developed by a fellow programmer. I am actually calling his program using PHP. I need to pass some variables to the program to control the C program to allow me to execute some commands.
As I mentioned previously, I managed to get the I have managed to trace the C program to the part where the error message is generated. In one of the functions, the program calls the function open('/path/to/file', O_RDWR). At this part of the program, the open() function should return me a value of 3 but instead when I call it from PHP, it returns a value -1 to me. why?? I have changed the permission of the the executable file "test" to allow users to read, write and execute, groups to read and execute and others to read and execute. In my Apache httpd.conf file, I have added the following <Directory "/usr/local/src/Application"> AllowOverride None Options None Order allow, deny Allow from all </Directory> In my php file, I call the C program using exec("/usr/local/src/Application/test", $rval. $result) I am really lost as to what is the problem Could someone please advice??? |
|
#4
|
|||
|
|||
|
Quote:
Change the folder´s permissions instead. The folder that your C program tries to write to. For a simple check if this is actually your problem, chmod it to 777 (rwxrwxrwx). |
|
#5
|
|||
|
|||
|
Hello. Thank you!!! Managed to solve it. Just had to give the other users the write privilege..
![]() |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Help with PHP calling C |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|