command work good
This commit is contained in:
parent
830a977272
commit
14e7abeedb
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/09 11:16:07 by apommier ### ########.fr */
|
/* Updated: 2022/03/09 11:37:23 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ void print_prompt(char **path)
|
|||||||
add_history(input);
|
add_history(input);
|
||||||
cmd = set_cmd(input, path);
|
cmd = set_cmd(input, path);
|
||||||
if (cmd)
|
if (cmd)
|
||||||
execute(cmd);
|
execute(cmd, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ typedef struct s_command {
|
|||||||
int main();//int ac, char **av, char **path);
|
int main();//int ac, char **av, char **path);
|
||||||
|
|
||||||
//pipe.c
|
//pipe.c
|
||||||
void execute(t_cmd *cmd);
|
void execute(t_cmd *cmd, char **env);
|
||||||
|
|
||||||
//set_cmd.c
|
//set_cmd.c
|
||||||
t_cmd *set_cmd(char *input, char **path);
|
t_cmd *set_cmd(char *input, char **path);
|
||||||
|
|||||||
13
pipe.c
13
pipe.c
@ -6,13 +6,13 @@
|
|||||||
/* 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 20:38:11 by apommier ### ########.fr */
|
/* Updated: 2022/03/09 11:37:06 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void execute(t_cmd *cmd)
|
void execute(t_cmd *cmd, char **env)
|
||||||
{
|
{
|
||||||
//save in/out
|
//save in/out
|
||||||
int ret;
|
int ret;
|
||||||
@ -23,11 +23,10 @@ void execute(t_cmd *cmd)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
//set the initial input
|
if (cmd->current_s_cmd->infile)//set the initial input
|
||||||
if (cmd->current_s_cmd->infile)//redirection
|
|
||||||
fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
||||||
else if (cmd->infile)//?
|
//else if (cmd->infile)
|
||||||
fdin = open(cmd->infile, O_RDONLY);
|
// fdin = open(cmd->infile, O_RDONLY);
|
||||||
else
|
else
|
||||||
fdin=dup(tmpin);
|
fdin=dup(tmpin);
|
||||||
while( i < cmd->nb_s_cmd)
|
while( i < cmd->nb_s_cmd)
|
||||||
@ -71,7 +70,7 @@ void execute(t_cmd *cmd)
|
|||||||
ret=fork();
|
ret=fork();
|
||||||
if(ret==0)
|
if(ret==0)
|
||||||
{
|
{
|
||||||
execve(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args, cmd->path);
|
execve(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args, env);//cmd->path);
|
||||||
//_exit(1);
|
//_exit(1);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user