set_cmd + exec
This commit is contained in:
parent
35f6c8bbaa
commit
43007c1c31
9
pipe.c
9
pipe.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/07 11:13:32 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;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
printf("in execute\n");
|
|
||||||
//set the initial input
|
//set the initial input
|
||||||
if (cmd->current_s_cmd->infile)
|
if (cmd->current_s_cmd->infile)
|
||||||
{
|
{
|
||||||
@ -43,7 +42,6 @@ void execute(t_cmd *cmd)
|
|||||||
}
|
}
|
||||||
while( i < cmd->nb_s_cmd)
|
while( i < cmd->nb_s_cmd)
|
||||||
{
|
{
|
||||||
printf("enter while\n");
|
|
||||||
if (i != 0 && cmd->current_s_cmd->infile)
|
if (i != 0 && cmd->current_s_cmd->infile)
|
||||||
fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
||||||
//redirect input
|
//redirect input
|
||||||
@ -52,7 +50,6 @@ void execute(t_cmd *cmd)
|
|||||||
//setup output
|
//setup output
|
||||||
if (i == cmd->nb_s_cmd - 1)
|
if (i == cmd->nb_s_cmd - 1)
|
||||||
{
|
{
|
||||||
printf("if last cmd\n");
|
|
||||||
// Last simple command
|
// Last simple command
|
||||||
if (cmd->current_s_cmd->outfile)
|
if (cmd->current_s_cmd->outfile)
|
||||||
fdout = open(cmd->current_s_cmd->outfile, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
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];
|
fdout=fdpipe[1];
|
||||||
fdin=fdpipe[0];
|
fdin=fdpipe[0];
|
||||||
}
|
}
|
||||||
printf("select if last or not done \n");
|
|
||||||
// Redirect output
|
// Redirect output
|
||||||
dup2(fdout,1);
|
dup2(fdout,1);
|
||||||
close(fdout);
|
close(fdout);
|
||||||
@ -82,13 +78,10 @@ void execute(t_cmd *cmd)
|
|||||||
if(ret==0)
|
if(ret==0)
|
||||||
{
|
{
|
||||||
return_exec = execvp(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args);
|
return_exec = execvp(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args);
|
||||||
printf("exec done ret exec= %d\n", return_exec);
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
printf("good i = %d\n", i);
|
|
||||||
} //while
|
} //while
|
||||||
printf("quit while\n");
|
|
||||||
//restore in/out defaults
|
//restore in/out defaults
|
||||||
dup2(tmpin,0);
|
dup2(tmpin,0);
|
||||||
dup2(tmpout,1);
|
dup2(tmpout,1);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/08 16:58:40 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;
|
i = 0;
|
||||||
if (exec[0][0] != '/')
|
if (exec[0][0] != '/')
|
||||||
swap = ft_strjoin(path[i], "/");
|
swap = ft_strjoin(path[i], "/");
|
||||||
|
cmd = ft_strjoin(swap, exec[0]);
|
||||||
|
free(swap);
|
||||||
|
swap = cmd;
|
||||||
while (access(swap, F_OK) && path[i++])
|
while (access(swap, F_OK) && path[i++])
|
||||||
{
|
{
|
||||||
free(swap);
|
free(swap);
|
||||||
@ -99,11 +102,8 @@ char *get_command(char **exec, char **path)
|
|||||||
char *swap;
|
char *swap;
|
||||||
|
|
||||||
swap = 0;
|
swap = 0;
|
||||||
printf("in get command exec=\n");
|
|
||||||
print_double(exec);
|
|
||||||
if (exec[0][0] == '/' && !access(exec[0], F_OK))
|
if (exec[0][0] == '/' && !access(exec[0], F_OK))
|
||||||
{
|
{
|
||||||
printf("first\n");
|
|
||||||
free_double(path);
|
free_double(path);
|
||||||
return (exec[0]);
|
return (exec[0]);
|
||||||
}
|
}
|
||||||
@ -114,6 +114,5 @@ char *get_command(char **exec, char **path)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
swap = does_access(path, exec);
|
swap = does_access(path, exec);
|
||||||
printf("swap bfore ret= %s\n", swap);
|
|
||||||
return (swap);
|
return (swap);
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/08 15:19:42 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, ' ');
|
split_line = ft_split(line, ' ');
|
||||||
s_cmd = malloc(sizeof(t_s_cmd));
|
s_cmd = malloc(sizeof(t_s_cmd));
|
||||||
s_cmd->cmd = get_command(split_line, cmd->path);
|
s_cmd->cmd = get_command(split_line, cmd->path);
|
||||||
printf("scmd= %s\n", s_cmd->cmd);
|
|
||||||
if (!s_cmd->cmd)
|
if (!s_cmd->cmd)
|
||||||
{
|
{
|
||||||
printf("get command crash");
|
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->infile = 0;
|
||||||
s_cmd->nb_args = double_size(split_line);
|
s_cmd->nb_args = double_size(split_line);
|
||||||
s_cmd->args = split_line;
|
s_cmd->args = split_line;
|
||||||
printf("args= %s\n", *(split_line));
|
|
||||||
s_cmd->outfile = 0;
|
s_cmd->outfile = 0;
|
||||||
return (s_cmd);
|
return (s_cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user