"more" as a target of piped command breaks bash

Posted by xavier on Stack Overflow See other posts from Stack Overflow or by xavier
Published on 2012-11-10T16:55:02Z Indexed on 2012/11/10 16:59 UTC
Read the original article Hit count: 194

Filed under:
|
|

Consider following source, reduced for simplicity

int main()
{
  int d[2];
  pipe(d);
  if(fork())
  {
    close(1);
    dup(d[1]);
    execlp("ls", "ls", NULL); 
  }
  else
  {
    close(0);
    dup(d[0]);
    execlp("cat", "cat", NULL); 
  }
}

So it creates a pipe and redirects the output from ls to cat.

It works perfectly fine, no problems. But change cat to more and bash breaks.

The symptoms are:

  • you don't see anything you type
  • pressing "enter" shows up a new prompt, but not in a new line, but in the same one
  • you can execute any command and see the output
  • reset helps fixing things up.

So there is a problem with input from keyboard, it is there, but is not visible.

Why is that?

© Stack Overflow or respective owner

Related posts about c

    Related posts about exec