mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
connec_cmd_execute: naive recursive pipe implementation (does not handle redirection)
This commit is contained in:
parent
df73b3d0c7
commit
6f75f2d181
1 changed files with 20 additions and 1 deletions
|
|
@ -6,12 +6,14 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/07 10:38:55 by khais #+# #+# */
|
/* Created: 2025/04/07 10:38:55 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/07 10:51:19 by khais ### ########.fr */
|
/* Updated: 2025/04/07 11:36:57 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "connec_cmd_execute.h"
|
#include "connec_cmd_execute.h"
|
||||||
#include "../cmd/cmd_execute.h"
|
#include "../cmd/cmd_execute.h"
|
||||||
|
#include "../common/do_waitpid.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||||
{
|
{
|
||||||
|
|
@ -27,10 +29,27 @@ static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||||
cmd_execute(cmd->second, app);
|
cmd_execute(cmd->second, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||||
|
{
|
||||||
|
int pid1;
|
||||||
|
int pid2;
|
||||||
|
|
||||||
|
pid1 = fork();
|
||||||
|
if (pid1 == 0)
|
||||||
|
cmd_execute(cmd->first, app);
|
||||||
|
pid2 = fork();
|
||||||
|
if (pid2 == 0)
|
||||||
|
cmd_execute(cmd->second, app);
|
||||||
|
do_waitpid(app, pid1);
|
||||||
|
do_waitpid(app, pid2);
|
||||||
|
}
|
||||||
|
|
||||||
void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||||
{
|
{
|
||||||
if (cmd->connector == FT_AND)
|
if (cmd->connector == FT_AND)
|
||||||
connec_and_cmd_execute(cmd, app);
|
connec_and_cmd_execute(cmd, app);
|
||||||
if (cmd->connector == FT_OR)
|
if (cmd->connector == FT_OR)
|
||||||
connec_or_cmd_execute(cmd, app);
|
connec_or_cmd_execute(cmd, app);
|
||||||
|
if (cmd->connector == FT_PIPE)
|
||||||
|
connec_pipe_cmd_execute(cmd, app);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue