Q:

More filter arguments with execlp

I've been trying to play with execlp() and came up with an idea. I want to execute a man command with more filter. Here is what i came up with:
void cmd_help(void)
{
  printf("shell command: help\n");
  execlp("/usr/bin/man", "man", "intro", "| more -8", NULL);
}

It shows the man intro page, but "| more -8" argument is not working. What can be the problem?

A:

With execlp you can only execute a single binary file and send some arguments to it. Services like I/O redirection or special char expansions will not work, even if they work on command line. This is because they are performed by shell interpreter before the actual command is invoked. To use them, you will need to invoke shell. For example:
void cmd_help(void)
{
  printf("shell command: help\n");
  execlp("/bin/bash", "bash", "-c", "man intro | more -8", NULL);
}

