B
Ben Chivers
I have a problem, which I think can be easily solved somehow.
I am trying to execute a C program through using a PHP script. I do
this by sending an exec command from the PHP script. My PHP script is
printed below:
<?php
system('main.exe');
?>
When I execute my PHP script, it only prints 'Hello World', and not
the output of the buffer in the C program. My C code is shown below:
#include <stdio.h>
int main()
{
printf("Hello World\n"); /* this prints fine on the php script */
char buffer[1024];
FILE *pipe;
pipe = popen("php -f testing.php", "r"); /* executing the php file
'testing.php' via the command line */
fread(buffer, 1, 1024, pipe);
printf("%s", buffer); /* this prints the output of the execution of
the PHP script */
pclose(pipe);
return 0;
}
Why does it do this? Is there a way around this issue?
If you execute the C program via the command line, the output of the
PHP script prints fine.
Any help with this issue would be most appreciated.
Many Regards,
Ben Chivers
I am trying to execute a C program through using a PHP script. I do
this by sending an exec command from the PHP script. My PHP script is
printed below:
<?php
system('main.exe');
?>
When I execute my PHP script, it only prints 'Hello World', and not
the output of the buffer in the C program. My C code is shown below:
#include <stdio.h>
int main()
{
printf("Hello World\n"); /* this prints fine on the php script */
char buffer[1024];
FILE *pipe;
pipe = popen("php -f testing.php", "r"); /* executing the php file
'testing.php' via the command line */
fread(buffer, 1, 1024, pipe);
printf("%s", buffer); /* this prints the output of the execution of
the PHP script */
pclose(pipe);
return 0;
}
Why does it do this? Is there a way around this issue?
If you execute the C program via the command line, the output of the
PHP script prints fine.
Any help with this issue would be most appreciated.
Many Regards,
Ben Chivers