I am using shell_exec function of PHP to execute a binary .exe file of a C program.
My C program takes an input text file and in output creates several text files. To integrate it with web front end, I am using php's shell_exec function to execute a shell script which in turn calls the binary C .exe file.
This binary .exe file , input text file ,shell script and the php file is on the server side. I have given chmod 777 access to the mentioned files on server side for testing purposes.
The extract in php executing shell script is as follows:
echo shell_exec('sh segments.sh 2>&1');
Now, here I am executing a shell script and the shell script runs the binary .exe file as follows:
->segments.sh
./auto_import.exe input_file.txt -terms
auto_import is the C binary .exe file.
When I run the shell script individually in my terminal, it gives me proper output. That is the output will be 4-5 different text files.
But when I call the shell script with PHP, I am not able to get any output and I am not sure how to receive output from my binary file which is number of text files.
I have tried providing absolute paths to my files for eg:
In php file shell script which is called by:
echo shell_exec('sh /path/segments.sh 2>&1');
In shell script , binary file is called as follows
echo shell_exec('sh /path/binary 2>&1');
I have also used exec function as follows:
$cmd = "/auto_import.exe input_file.txt -terms"; echo exec($cmd,$output);
Could you gives help me out in this regard?