Skip to content

Commit 3589255

Browse files
committed
uncomment pipes handling function implementation for unix and make a corresponding check for the type of os
1 parent d54a11e commit 3589255

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/pipeline.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,23 @@ pipeline_pipes_handle(pipe_cmds_t* pipe_commands)
152152
char** args1 = command_args_to_string_array(comm1);
153153
command_t* comm2 = pipe_commands->cmds_list[1];
154154
char** args2 = command_args_to_string_array(comm2);
155-
//pipe(pipefd);
156-
//if (fork() == 0) {
157-
// //child
158-
// //write
159-
// close(pipefd[0]);
160-
// dup2(pipefd[1], STDOUT_FILENO);
161-
// execvp(comm1->name, args1);
162-
//} else {
163-
// //parent
164-
// close(pipefd[1]);
165-
// dup2(pipefd[0], STDIN_FILENO);
166-
// execvp(comm2->name, args2);
167-
//}
168-
printf("Pipes have been successfully handled\n");
155+
#ifdef __unix__
156+
pipe(pipefd);
157+
if (fork() == 0) {
158+
//child
159+
//write
160+
close(pipefd[0]);
161+
dup2(pipefd[1], STDOUT_FILENO);
162+
execvp(comm1->name, args1);
163+
} else {
164+
//parent
165+
close(pipefd[1]);
166+
dup2(pipefd[0], STDIN_FILENO);
167+
execvp(comm2->name, args2);
168+
}
169+
#elif _WIN32
170+
171+
#endif
169172

170173
return 0;
171174
}

0 commit comments

Comments
 (0)