This is a school project I'm working on.
I'm writing a web server. If the requested resource has the extension 'cgi', I need to fork and exec the program. If the cgi is a compiled executable, this works:
execl(path, (char*) 0);
But if the cgi program is a script that needs to be interpreted, I need to do something like this:
execl("/bin/sh", path, path, (char*) 0);
How can I write my code so it will handle either scenario? How does my shell do this? Should I use the file
program to determine if it's an executable or text, and if it's text, then assume it needs to be interpreted?
Why do you need to invoke "/bin/sh"
explicitly if it's a script?
As long as the script has execute permission and the proper shebang at the top, you should be able to execute it just as if it were an executable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With