summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-04-30 17:40:06 +0200
committerDominik Kaiser2024-04-30 17:40:06 +0200
commit2692c96e1e4a995b0315ece2888e3255a205b802 (patch)
tree329a9bd2585365c89086205500ce9ac25baedced /src/main.c
parent87f506fc6edf8140cc6ec1aede38bb316a2e4933 (diff)
downloadpipex-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
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 01c022a..1fdc764 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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])
}