blob: 1fdc764d3c09e234f51b1654d7809ea6c0705033 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 13:35:21 by dkaiser #+# #+# */
/* Updated: 2024/04/30 17:37:09 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
#include <unistd.h>
#include <fcntl.h>
int main(void)
{
char *args1[] = {"/bin/cat", 0};
char *args2[] = {"/usr/bin/grep", "libft", 0};
int p[2];
pipe(p);
pid_t pid = fork();
if (pid < 0)
{
exit(1);
}
if (pid == 0)
{
close(p[0]);
int infd = open("in.txt", O_RDONLY);
dup2(infd, 0);
dup2(p[1], 1);
execve(args1[0], args1, NULL);
}
else
{
wait(NULL);
close(p[1]);
dup2(p[0], 0);
int outfd = open("out.txt", O_WRONLY);
dup2(outfd, 1);
execve(args2[0], args2, NULL);
}
}
|