aboutsummaryrefslogtreecommitdiff
path: root/src/execute_cmd.c
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-22 16:50:05 +0100
committerChristopher Uhlig2025-01-22 16:50:05 +0100
commitad5eae00584c6c4a88e873b85645c10c47cd7bf8 (patch)
tree77d00c9f815d26b05594fe75c11e364b3568e3ec /src/execute_cmd.c
parentf6e474d27a1398c6d4f2e88c7f2d3797b85217da (diff)
downloadminishell-ad5eae00584c6c4a88e873b85645c10c47cd7bf8.tar.gz
minishell-ad5eae00584c6c4a88e873b85645c10c47cd7bf8.zip
uiuiuiui
Diffstat (limited to 'src/execute_cmd.c')
-rw-r--r--src/execute_cmd.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/execute_cmd.c b/src/execute_cmd.c
index 012391f..2179515 100644
--- a/src/execute_cmd.c
+++ b/src/execute_cmd.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:21:35 by chuhlig #+# #+# */
-/* Updated: 2025/01/21 23:52:38 by chuhlig ### ########.fr */
+/* Updated: 2025/01/22 16:29:34 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,12 +17,22 @@
static void establish_pipeline(int original_stdin, int original_stdout);
static int exec_cmd(t_cmd *cmd, t_env **env, int original_std[2], int result);
+int invalid_input(char *cmd)
+{
+ ft_putstr_fd("minishell: ", STDERR_FILENO);
+ ft_putstr_fd(cmd, STDERR_FILENO);
+ ft_putstr_fd(": command not found\n", STDERR_FILENO);
+ return (127);
+}
+
int is_builtin(char *cmd)
{
- return ((ft_strcmp(cmd, "export") == 0) || (ft_strcmp(cmd, "unset") == 0)
+ if ((ft_strcmp(cmd, "export") == 0) || (ft_strcmp(cmd, "unset") == 0)
|| (ft_strcmp(cmd, "cd") == 0) || (ft_strcmp(cmd, "exit") == 0)
|| (ft_strcmp(cmd, "echo") == 0) || (ft_strcmp(cmd, "pwd") == 0)
- || (ft_strcmp(cmd, "env") == 0));
+ || (ft_strcmp(cmd, "env") == 0))
+ return (1);
+ return(invalid_input(cmd));
}
int execute_builtin(char **args, t_env **env)
@@ -96,7 +106,7 @@ static int exec_cmd(t_cmd *cmd, t_env **env, int original_std[2], int result)
cmd_path = get_cmd_path(cmd->args[i], *env, &result);
if (cmd_path != NULL)
execve(cmd_path, &(cmd->args[i]), env_to_strlst(*env));
- free(cmd_path);
+ // free(cmd_path);
exit(result);
}
waitpid(pid, &status, 0);