set_cmd + exec

This commit is contained in:
kinou-p 2022-03-08 18:34:47 +01:00
parent 35f6c8bbaa
commit 43007c1c31
3 changed files with 6 additions and 16 deletions

9
pipe.c
View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}