I am executing a C program i.e. '.exe' that is an executable file from PHP.
I have an interface with an HTML which calls a PHP file whenever I click a button.
On PHP, it calls up a shell script. So on PHP, I use the following:
echo shell_exec('sh auto_script.sh');
The shell file executes the program .exe as follows:
./import -file.txt
where import
is my executable C program .exe and file.txt is an input which I am hard coding as of now.
Executable file 'import' is stored in the same direcotry as php file called.
When I execute the shell script on a terminal, it executes properly with the necessary output.
But when I try to execute it from PHP it doesnt work. I have given full permissions to file as of now.
A quick check on the [ shell_exec ] manpage says shell_exec
has the following definition :
string shell_exec ( string $cmd )
which means that the argument should be a string, which indeed means it should be inside quotes. BTW, you don't need a mediator script here anyways, So do :
echo shell_exec('./import "-file.txt"'); //Using relative paths
Having said that placing the binary in the scripts folder is a bad idea, but I hope above helps you to get you going.