simple redirection work and double output
This commit is contained in:
parent
0981534a07
commit
795ad81851
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
|
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/10 00:17:00 by apommier ### ########.fr */
|
/* Updated: 2022/03/10 11:39:08 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -73,5 +73,6 @@ void exit_shell(t_cmd *cmd);
|
|||||||
|
|
||||||
//redirection.c set redirection and input good
|
//redirection.c set redirection and input good
|
||||||
char *set_redirection(t_s_cmd *cmd, char *line);
|
char *set_redirection(t_s_cmd *cmd, char *line);
|
||||||
|
char next_space(char *str, int i);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -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/10 00:16:05 by apommier ### ########.fr */
|
/* Updated: 2022/03/10 11:07:08 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ void print_prompt(char **path)
|
|||||||
free(input);
|
free(input);
|
||||||
exit_shell(cmd);
|
exit_shell(cmd);
|
||||||
}
|
}
|
||||||
if (ft_strlen(input))
|
if (ft_strlen(input) && next_space(input, 0))
|
||||||
{
|
{
|
||||||
add_history(input);
|
add_history(input);
|
||||||
cmd = set_cmd(input, path);
|
cmd = set_cmd(input, path);
|
||||||
|
|||||||
@ -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/09 20:43:42 by apommier ### ########.fr */
|
/* Updated: 2022/03/10 11:38:53 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,7 +24,8 @@ void execute(t_cmd *cmd, char **env)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (cmd->current_s_cmd->infile)//set the initial input
|
if (cmd->current_s_cmd->infile)//set the initial input
|
||||||
fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
fdin = open(cmd->current_s_cmd->infile, O_APPEND);
|
||||||
|
//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
|
||||||
@ -34,7 +35,8 @@ void execute(t_cmd *cmd, char **env)
|
|||||||
//if (i)
|
//if (i)
|
||||||
// cmd->current_s_cmd++;
|
// cmd->current_s_cmd++;
|
||||||
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_CREAT | O_APPEND);
|
||||||
|
//fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
||||||
//redirect input
|
//redirect input
|
||||||
dup2(fdin, 0);
|
dup2(fdin, 0);
|
||||||
close(fdin);
|
close(fdin);
|
||||||
@ -44,7 +46,7 @@ void execute(t_cmd *cmd, char **env)
|
|||||||
{
|
{
|
||||||
// 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_APPEND, 0666);
|
||||||
else if(cmd->outfile)
|
else if(cmd->outfile)
|
||||||
fdout=open(cmd->outfile, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
fdout=open(cmd->outfile, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||||
else// Use default output
|
else// Use default output
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/10 02:40:46 by apommier ### ########.fr */
|
/* Updated: 2022/03/10 11:47:21 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -156,6 +156,17 @@ char *ft_output(char *line, t_s_cmd *cmd, int index)
|
|||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_file(char *file)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open(file, O_CREAT | O_TRUNC);
|
||||||
|
if (fd)
|
||||||
|
close(fd);
|
||||||
|
if (fd == -1)
|
||||||
|
error_redirect();
|
||||||
|
}
|
||||||
|
|
||||||
char *set_redirection(t_s_cmd *cmd, char *line)
|
char *set_redirection(t_s_cmd *cmd, char *line)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -167,11 +178,15 @@ char *set_redirection(t_s_cmd *cmd, char *line)
|
|||||||
if(line[i] == '<')
|
if(line[i] == '<')
|
||||||
{
|
{
|
||||||
line = ft_input(line, cmd, i);
|
line = ft_input(line, cmd, i);
|
||||||
|
//if (cmd->in_type == 1)
|
||||||
|
// set_file(cmd->infile);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
else if(line[i] == '>')
|
else if(line[i] == '>')
|
||||||
{
|
{
|
||||||
line = ft_output(line, cmd, i);
|
line = ft_output(line, cmd, i);
|
||||||
|
if (cmd->in_type == 0)
|
||||||
|
set_file(cmd->outfile);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user