Hello there,
I'm new to PHP. I'm trying to run a simple php
script (on a Red hat linux machine with apache web server )
through a windows web browser (IE).
I'm using an exec() function in my php script.
The code is given below (with line numbers).
01 <?php
02 $output = exec("pwd");
03 echo "<br>Workin g dir: $output";
04 //$prgfile="touch out/testfile";
05 //$prgfile="ls";
06 //$prgfile="./hello.pl";
07 $prgfile="./hello";
08 exec($prgfile, $output, $rc);
09 echo "<br>";
10 print_r($output );
11 echo "<br> Return Value: ";
12 print_r($rc);
13 //$output = system($prgfile , $rc);
14 //var_dump($outpu t);
15 //var_dump($rc);
16 ?>
The exec() and system() functions works when I
use any shell command (as in lines 2, 4, 5)
or a perl script (line 6). hello.pl prints a
"hello world" to the browser. "pwd" prints
the current working dir.
But when I use a C/C++ binary (line 7), "hello"
executable should print "hello world" to browser,
the script gives me a return code of 126 and the
$output is empty. But when I run the script from
linux shell prompt I can see the output.
The apache error log says
sh: ./hello: cannot execute binary file.
I guess, the fix should be simple but I don't
know what I'm missing here. I changed the permissions
of "hello" to 777, gave absolute path but still no output.
=============== =============== =============== ====
The C/C++ code I used to create "hello"
(I compiled them with gcc/g++ and both runs).
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
=============== =============== =============== ====
Any help is appreciated.
Thanks,
Hemanth
I'm new to PHP. I'm trying to run a simple php
script (on a Red hat linux machine with apache web server )
through a windows web browser (IE).
I'm using an exec() function in my php script.
The code is given below (with line numbers).
01 <?php
02 $output = exec("pwd");
03 echo "<br>Workin g dir: $output";
04 //$prgfile="touch out/testfile";
05 //$prgfile="ls";
06 //$prgfile="./hello.pl";
07 $prgfile="./hello";
08 exec($prgfile, $output, $rc);
09 echo "<br>";
10 print_r($output );
11 echo "<br> Return Value: ";
12 print_r($rc);
13 //$output = system($prgfile , $rc);
14 //var_dump($outpu t);
15 //var_dump($rc);
16 ?>
The exec() and system() functions works when I
use any shell command (as in lines 2, 4, 5)
or a perl script (line 6). hello.pl prints a
"hello world" to the browser. "pwd" prints
the current working dir.
But when I use a C/C++ binary (line 7), "hello"
executable should print "hello world" to browser,
the script gives me a return code of 126 and the
$output is empty. But when I run the script from
linux shell prompt I can see the output.
The apache error log says
sh: ./hello: cannot execute binary file.
I guess, the fix should be simple but I don't
know what I'm missing here. I changed the permissions
of "hello" to 777, gave absolute path but still no output.
=============== =============== =============== ====
The C/C++ code I used to create "hello"
(I compiled them with gcc/g++ and both runs).
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
=============== =============== =============== ====
Any help is appreciated.
Thanks,
Hemanth
Comment