summaryrefslogtreecommitdiff
path: root/src/shell_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-09-06 14:28:07 +0200
committerMaxime Coste <frrrwww@gmail.com>2012-09-06 14:28:07 +0200
commit96beaf50ddf7f70d7f52554b83241edc417fddbb (patch)
treec967f3edf564a9243dcfad9e282c83f743cbeff8 /src/shell_manager.cc
parentddd5236b08628e092f20bd5b7952b2891c093118 (diff)
ShellManager: output stderr in the debug buffer
Diffstat (limited to 'src/shell_manager.cc')
-rw-r--r--src/shell_manager.cc25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 81643dad..cb6e94c7 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -1,5 +1,7 @@
#include "shell_manager.hh"
+#include "debug.hh"
+
#include <cstring>
#include <sys/types.h>
#include <sys/wait.h>
@@ -23,17 +25,20 @@ String ShellManager::pipe(const String& input,
const String& cmdline, const Context& context,
const EnvVarMap& env_vars)
{
- int write_pipe[2];
- int read_pipe[2];
+ int write_pipe[2]; // child stdin
+ int read_pipe[2]; // child stdout
+ int error_pipe[2]; // child stderr
::pipe(write_pipe);
::pipe(read_pipe);
+ ::pipe(error_pipe);
String output;
if (pid_t pid = fork())
{
close(write_pipe[0]);
close(read_pipe[1]);
+ close(error_pipe[1]);
memoryview<char> data = input.data();
write(write_pipe[1], data.pointer(), data.size());
@@ -47,14 +52,30 @@ String ShellManager::pipe(const String& input,
output += String(buffer, buffer+size);
}
close(read_pipe[0]);
+
+ String errorout;
+ while (size_t size = read(error_pipe[0], buffer, 1024))
+ {
+ if (size == -1)
+ break;
+ errorout += String(buffer, buffer+size);
+ }
+ close(error_pipe[0]);
+ if (not errorout.empty())
+ {
+ write_debug("\nshell stderr: <<<\n" + errorout + ">>>\n");
+ }
+
waitpid(pid, NULL, 0);
}
else try
{
close(write_pipe[1]);
close(read_pipe[0]);
+ close(error_pipe[0]);
dup2(read_pipe[1], 1); close(read_pipe[1]);
+ dup2(error_pipe[1], 2); close(error_pipe[1]);
dup2(write_pipe[0], 0); close(write_pipe[0]);
boost::regex_iterator<String::iterator> it(cmdline.begin(), cmdline.end(), m_regex);