问题
Hi I am unable to run the .sh file using my php code.
Files: index.php and .sh files are in the same directory.
What I have tried:
echo shell_exec('sh shell_file.sh'); //Did not execute
echo shell_exec('shell_file.sh'); //Did not execute
echo exec('shell_file.sh'); //Did not execute
But when I run the shell_file.sh file manually it does execute.
回答1:
Try like this:
What you need to do is call the file with a program. Call it with bash or sh as suggested in the comment:
echo shell_exec('sh /shell_file.sh');
Another option could be:
$contents = file_get_contents('/shell_file.sh');
echo shell_exec($contents);
I think the first option would be better however.
来源:https://stackoverflow.com/questions/30507840/unable-to-run-shell-script-file-using-php