From 43007c1c31bee798cc5a4141b8476edb1a37e102 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Tue, 8 Mar 2022 18:34:47 +0100 Subject: [PATCH] set_cmd + exec --- pipe.c | 9 +-------- pipex_utils.c | 9 ++++----- set_cmd.c | 4 +--- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/pipe.c b/pipe.c index a33d8ff..cef3bf6 100644 --- a/pipe.c +++ b/pipe.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/03/07 11:13:32 by apommier #+# #+# */ -/* Updated: 2022/03/08 17:16:44 by apommier ### ########.fr */ +/* Updated: 2022/03/08 18:33:51 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,6 @@ void execute(t_cmd *cmd) int i; i = 0; - printf("in execute\n"); //set the initial input if (cmd->current_s_cmd->infile) { @@ -43,7 +42,6 @@ void execute(t_cmd *cmd) } while( i < cmd->nb_s_cmd) { - printf("enter while\n"); if (i != 0 && cmd->current_s_cmd->infile) fdin = open(cmd->current_s_cmd->infile, O_RDONLY); //redirect input @@ -52,7 +50,6 @@ void execute(t_cmd *cmd) //setup output if (i == cmd->nb_s_cmd - 1) { - printf("if last cmd\n"); // Last simple command if (cmd->current_s_cmd->outfile) fdout = open(cmd->current_s_cmd->outfile, O_RDWR | O_CREAT | O_TRUNC, 0666); @@ -71,7 +68,6 @@ void execute(t_cmd *cmd) fdout=fdpipe[1]; fdin=fdpipe[0]; } - printf("select if last or not done \n"); // Redirect output dup2(fdout,1); close(fdout); @@ -82,13 +78,10 @@ void execute(t_cmd *cmd) if(ret==0) { return_exec = execvp(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args); - printf("exec done ret exec= %d\n", return_exec); _exit(1); } i++; - printf("good i = %d\n", i); } //while - printf("quit while\n"); //restore in/out defaults dup2(tmpin,0); dup2(tmpout,1); diff --git a/pipex_utils.c b/pipex_utils.c index 4527151..4abbe0d 100644 --- a/pipex_utils.c +++ b/pipex_utils.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/03/08 16:58:40 by apommier #+# #+# */ -/* Updated: 2022/03/08 18:02:15 by apommier ### ########.fr */ +/* Updated: 2022/03/08 18:32:29 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,6 +81,9 @@ char *does_access(char **path, char **exec) i = 0; if (exec[0][0] != '/') swap = ft_strjoin(path[i], "/"); + cmd = ft_strjoin(swap, exec[0]); + free(swap); + swap = cmd; while (access(swap, F_OK) && path[i++]) { free(swap); @@ -99,11 +102,8 @@ char *get_command(char **exec, char **path) char *swap; swap = 0; - printf("in get command exec=\n"); - print_double(exec); if (exec[0][0] == '/' && !access(exec[0], F_OK)) { - printf("first\n"); free_double(path); return (exec[0]); } @@ -114,6 +114,5 @@ char *get_command(char **exec, char **path) exit(1); } swap = does_access(path, exec); - printf("swap bfore ret= %s\n", swap); return (swap); } \ No newline at end of file diff --git a/set_cmd.c b/set_cmd.c index e5e1a67..e97fc20 100644 --- a/set_cmd.c +++ b/set_cmd.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/03/08 15:19:42 by apommier #+# #+# */ -/* Updated: 2022/03/08 18:04:06 by apommier ### ########.fr */ +/* Updated: 2022/03/08 18:33:53 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,6 @@ t_s_cmd *set_s_cmd(char *line, t_cmd *cmd) split_line = ft_split(line, ' '); s_cmd = malloc(sizeof(t_s_cmd)); s_cmd->cmd = get_command(split_line, cmd->path); - printf("scmd= %s\n", s_cmd->cmd); if (!s_cmd->cmd) { printf("get command crash"); @@ -41,7 +40,6 @@ t_s_cmd *set_s_cmd(char *line, t_cmd *cmd) s_cmd->infile = 0; s_cmd->nb_args = double_size(split_line); s_cmd->args = split_line; - printf("args= %s\n", *(split_line)); s_cmd->outfile = 0; return (s_cmd); }