diff options
| author | Dominik Kaiser | 2024-04-30 17:40:06 +0200 |
|---|---|---|
| committer | Dominik Kaiser | 2024-04-30 17:40:06 +0200 |
| commit | 2692c96e1e4a995b0315ece2888e3255a205b802 (patch) | |
| tree | 329a9bd2585365c89086205500ce9ac25baedced | |
| parent | 87f506fc6edf8140cc6ec1aede38bb316a2e4933 (diff) | |
| download | pipex-2692c96e1e4a995b0315ece2888e3255a205b802.tar.gz pipex-2692c96e1e4a995b0315ece2888e3255a205b802.zip | |
Fast and bad solution
This is just to get a feeling on how to solve the problem in general
| -rw-r--r-- | src/main.c | 43 |
1 files changed, 34 insertions, 9 deletions
@@ -6,19 +6,44 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/29 13:35:21 by dkaiser #+# #+# */ -/* Updated: 2024/04/29 15:27:14 by dkaiser ### ########.fr */ +/* Updated: 2024/04/30 17:37:09 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ #include "pipex.h" +#include <unistd.h> +#include <fcntl.h> -int main(int argc, char *argv[]) { - if (argc != 5) - return (1); +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); + } - // Read content of file1 (argv[1]) - // Execute cmd1 (argv[2]) with file1 on stdin - // pipe the output of cmd1 into cmd2 - // Execute cmd2 (argv[3]) with the piped input on stdin - // Write output of cmd2 into file2 (argv[4]) } |
