So I was given this code:
execlp("sh", "sh", "-c", string, (char*) 0);
In class, and told to udnerstand it. I’ve been looking up the execlp API like crazy, but I still don’t fully understand what this code is doing.
My best guess:
“sh” is the filepath
“-c” is the argument
string is the command
(char*)0 is the null terminator.
I can’t seem to figure out why there are two instances of “sh” in the code:
I was guessing that -c means copy, and that the command is executing a copy from one file to another, using the string command, but I’m not 100% on that.
Any clarification would be greatly appreciated.
Thank you.
The first argument is the file name to execute (in this case it’s the sh command). The first argument to it should be the name of the executable (hence the repeated “sh”), -c is another argument to the sh exe that tells it to read commands from the command string. string is (I’m guessing) the commands that sh should execute and the (char *)0 is just an ending marker.
Let me know if I left something out you wanted explained.