I want to learn how to use pipes in C, and tried to do basic things like for example cloning the behaviour of |
in shell.
This is my first try:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
FILE *stdin_tmp;
stdin_tmp = stdin;
stdin = stdout;
system("cat /tmp/test.txt");
system("less");
stdin = stdin_tmp;
return 0;
}
This is what I want to do (written in shell):
cat /tmp/test.txt |less
The behaviour is obviously not what I expected. less
isn't receiving the output of cat
.
How is it done correctly?