From e29af1f554ee40a888689e134e12f8d4a3b24ea1 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Thu, 21 May 2020 11:49:54 +0200 Subject: cmake --- 02_exercise/.gitignore | 1 - 02_exercise/CMakeLists.txt | 5 +++++ 02_exercise/shell.c | 9 +++------ 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 02_exercise/CMakeLists.txt diff --git a/02_exercise/.gitignore b/02_exercise/.gitignore index acfd225..5aacf99 100644 --- a/02_exercise/.gitignore +++ b/02_exercise/.gitignore @@ -1,3 +1,2 @@ -CMakeLists.txt prog shell diff --git a/02_exercise/CMakeLists.txt b/02_exercise/CMakeLists.txt new file mode 100644 index 0000000..0cf7c20 --- /dev/null +++ b/02_exercise/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.5) + +project(shell) + +add_executable(shell array.c shell.c) \ No newline at end of file diff --git a/02_exercise/shell.c b/02_exercise/shell.c index f48819b..5a8d48f 100644 --- a/02_exercise/shell.c +++ b/02_exercise/shell.c @@ -122,17 +122,14 @@ int exec_command(const char *path, char *const argv[], unsigned timeout) { close(pipefd[1]); size_t length = 0; - if ((length = read(pipefd[0], buf, 512)) <= 0) { - fprintf(stderr, "error\n"); - exit(-3); + while ((length = read(pipefd[0], buf, 10)) > 0) { + buf[length] = '\0'; + printf("%s", buf); } waitpid(pid, &status, 0); close(pipefd[0]); - buf[length] = '\0'; - - printf("%s", buf); return WEXITSTATUS(status); } \ No newline at end of file -- cgit v1.2.3-54-g00ecf