summaryrefslogtreecommitdiff
path: root/userspace/piper.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-21 01:43:25 +0200
committerMiguel <m.i@gmx.at>2018-09-21 01:43:25 +0200
commitace0646608c393d8952b14536090c302bed2ee85 (patch)
tree5d96e0d0a66c27818b677af3a84ef52af0260be1 /userspace/piper.c
parentaeefdb37d1fc1c0eb7953b9c196cab09460bc167 (diff)
piperei working finally :)
Diffstat (limited to 'userspace/piper.c')
-rw-r--r--userspace/piper.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/userspace/piper.c b/userspace/piper.c
index f45248e..80cbd27 100644
--- a/userspace/piper.c
+++ b/userspace/piper.c
@@ -1,38 +1,27 @@
#include <stdio.h>
#include "newcalls.h"
+extern **environ;
+
int main()
{
int fds[2];
_pipe(fds);
- printf("opened pipe / in fd=%d,out fd=%d\n",fds[0],fds[1]);
-
int pid=_fork();
if(pid)
{
- while(1) // read forever from our pipe and echo to stdout
- {
- char buf[256];
- int len=fread(buf,1,255,fds[0]);
- //int len=_read(fds[0],buf,255);
- buf[len]=0;
- printf("-\n");
- printf("%s\n",buf);
- printf("-\n");
- }
-
+ _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
{
-
- // write to our pipe
- _write(fds[1],"Hello\n",fds[1]);
- _write(fds[1],"Bello\n",fds[1]);
-
- // hang forever
- while(1);
+ _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);
}
-
}