diff options
Diffstat (limited to '02_exercise')
-rw-r--r-- | 02_exercise/.gitignore | 1 | ||||
-rw-r--r-- | 02_exercise/CMakeLists.txt | 5 | ||||
-rw-r--r-- | 02_exercise/shell.c | 9 |
3 files changed, 8 insertions, 7 deletions
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 |