I want to create my own pipeline like in Unix terminal (just to practice). It should take applications to execute in quotes like that:
pipeline "ls -l" "grep" ....
I know that I should use fork()
, execl()
(exec*
) and API to redirect stdin and stdout. But are there any alternatives for execl
to execute app with arguments using just one argument which includes application path and arguments? Is there a way not to parse manually ls -l
but pass it as one argument to execl
?
If you have only a single command line instead of an argument vector, let the shell do the parsing for you:
execl("/bin/sh", "sh", "-c", the_command_line, NULL);
Of course, don't let untrusted remote user input into this command line. But if you are dealing with untrusted remote user input to begin with, you should try to arrange to pass actual a list of isolated arguments to the target application as per normal usage of exec[vl]
, not a command line.