From 1673be16cbf92aeb314da51d3215283dad31e207 Mon Sep 17 00:00:00 2001 From: Steven YANG <steven.yang.ys@gmail.com> Date: Sun, 15 Dec 2024 13:30:12 +0100 Subject: [PATCH] bug affichage redirection --- main.c | 2 +- shell.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 33f06a1..97546d6 100644 --- a/main.c +++ b/main.c @@ -28,7 +28,7 @@ int main(void) { char* buffer = malloc(sizeof(char)); lireCommande(buffer, historique); - if (strlen(buffer) > 1) { + if (strlen(buffer) > 0) { ajouterHistorique(&historique, buffer); if (strcmp(buffer, "history") == 0) { afficherHistorique(historique); diff --git a/shell.c b/shell.c index bb01d95..3e04164 100644 --- a/shell.c +++ b/shell.c @@ -65,7 +65,11 @@ void executerCommande(char** arguments) { int nbytes; while ((nbytes = read(pipe_fd[0], buffer, MAX_SIZE_BUFFER - 1)) > 0) { buffer[nbytes] = '\0'; - printw("%s", buffer); + if (isatty(STDOUT_FILENO)) { + printw("%s", buffer); + } else { + printf("%s", buffer); + } } close(pipe_fd[0]); } -- GitLab