summaryrefslogtreecommitdiff
path: root/src/shell_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-06-08 22:42:51 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-06-08 22:42:51 +0100
commit409d804ee85074eed8bd94f616bc23284bdf5eb9 (patch)
treeac725706d8155d1141be6fb366aa1840bb2f9beb /src/shell_manager.cc
parent6cb7e20d54984494d98589213119a9e2accb0317 (diff)
Do not close stderr/stdout before program finish
Programs like grep called in '$' command will fail due to SIGPIPE for example. So we need to keep the pipe open.
Diffstat (limited to 'src/shell_manager.cc')
-rw-r--r--src/shell_manager.cc16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index ff483d89..3a64eef2 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -60,20 +60,18 @@ std::pair<String, int> ShellManager::eval(
FDWatcher stdout_watcher{read_pipe[0], pipe_reader(child_stdout)};
FDWatcher stderr_watcher{error_pipe[0], pipe_reader(child_stderr)};
- if (not (flags & Flags::ReadOutput))
- {
- stdout_watcher.close_fd();
- stderr_watcher.close_fd();
- }
-
- while (not stdout_watcher.closed() or
- not stderr_watcher.closed() or
- not terminated)
+ while (not terminated or
+ ((flags & Flags::WaitForStdout) and
+ (not stdout_watcher.closed() or
+ not stderr_watcher.closed())))
{
EventManager::instance().handle_next_events(EventMode::Urgent);
if (not terminated)
terminated = waitpid(pid, &status, WNOHANG);
}
+
+ stdout_watcher.close_fd();
+ stderr_watcher.close_fd();
}
if (not child_stderr.empty())