ls -l | less ls -l | less is actually a shell command line consisting of two processes connected by a pipe. A call to execvp() can spawn only one process.
If you want to do this from your program, you must explicitly call the shell - either by calling system() , or by changing the command line to sh -c 'ls -l | less' sh -c 'ls -l | less' . Your word array should look like this:
word[0] = "sh" word[1] = "-c" word[2] = "ls -l | less" word[3] = NULL
[EDIT] Alternatively, you can do what the shell does internally: create two processes and link them to the channel. This involves using calls to fork() , pipe() , dup2() and execve() . However, the shell call is much smaller, and since less is an interactive program, in any case you do not need to worry about performance: everything that takes less than 100 ms is perceived as instantaneous.
source share