summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-05-21 11:49:54 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-05-21 11:50:12 +0200
commite29af1f554ee40a888689e134e12f8d4a3b24ea1 (patch)
tree64c3a26f17a82fe2da03dfd27d743bc7d05bde35
parent5a200f8b131917d2e6d51df50b01042ffaafa9a6 (diff)
downloadbetriebssysteme-e29af1f554ee40a888689e134e12f8d4a3b24ea1.tar.gz
betriebssysteme-e29af1f554ee40a888689e134e12f8d4a3b24ea1.zip
cmake
-rw-r--r--02_exercise/.gitignore1
-rw-r--r--02_exercise/CMakeLists.txt5
-rw-r--r--02_exercise/shell.c9
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