summaryrefslogtreecommitdiff
path: root/userspace/piper.c
blob: 80cbd271bda45d075a275b660283aa81f9b8528e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include "newcalls.h"

extern **environ;

int main()
{
    int fds[2];
    _pipe(fds);

    int pid=_fork();

    if(pid)
    {
	_close(fds[1]);
	_dup2(fds[0],0); // replace stdin with the read-end of pipe
	char *args[]={"grep",NULL};
	_execve("/bin/grep",args,environ);
    }
    else
    {
	_close(fds[0]);
	_dup2(fds[1],1); // replace stdout with the write-end of our pipe
	char *args[]={"cat","hello.txt",0};
	_execve("/bin/cat",args,environ);
    }
}