I want to run something like
cat file.tar | base64 | myprogram -c "| base64 -d | tar -zvt "
I use execlp to run the process.
When i try to run something like cat it works, but if i try to run base64 -d | tar -zvt it doesn’t work.
I looked at the bash commands and I found out that I can run bash and tell him to run other programs. So it’s something like:
execlp ("bash", "-c", "base64 -d | tar -zvt", NULL);
If I run it on the terminal, it works well, but using the execlp it dont work.
If I use execlp("cat", "cat", NULL) it works.
Someone knows how to use the -c param on execlp to execute multiple “programs”?
I cant use system because i use pipe and fork.
Now i noticed, if i try to use execlp(“bash”, “bash”, “-c”, “base64”, NULL)… nothing happens.
If i use execlp(“cat”, NULL) it’s ok..
I’m writing to the stdin… i don’t know if its the problem with the bash -c base64.. because if i run on the terminal echo “asd” | bash -c “cat”
it goes well
The first “argument” is what becomes
argv[0], so you should call with something like:Edit A small explanation what the above function does: The
execfamily of functions executes a program. In the above call the program in question is “bash” (first argument). Bash, like all other programs, have amainfunction that is the starting point of the program. And like all othermainfunctions, the one in Bash receives two arguments, commonly calledargcandargv.argvis an array of zero-terminated strings, andargcis the number of entries in theargvarray.argcwill always be at least 1, meaning that there is always one entry atargv[0]. This first entry is the “name” of the program, most often the path of the program file. All other program arguments on the command line is put intoargv[1]toargv[argc - 1].What
execlpdoes is use the first argument to find the program to be executed, and all the other arguments will be put into the programsargvarray in the order they are given. This means that the above call toexeclpwill call the program “bash” and set theargvarray of Bash to this:Also,
argcof Bash will be set to 3.If the second
"bash"is changed to"foo", thenargv[0]of Bash will be set to"foo"as well.I hope this clears it up a little bit.