X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSystem%2FUnix%2FProgram.inc;h=cdc6fee609491c28f938fcb34f1199229d6815f7;hb=a26eae64ddf607549f9e47046d46ea5b9ec648b4;hp=6ff69ca133e443878d683e9aea3f2178626ec8c2;hpb=905261efed461e2b9dd505a2569f7f9315906c71;p=oota-llvm.git diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index 6ff69ca133e..cdc6fee6094 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -99,7 +99,7 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) { int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666); if (InFD == -1) { MakeErrMsg(ErrMsg, "Cannot open file '" + File + "' for " - + (FD == 0 ? "input" : "output") + "!\n"); + + (FD == 0 ? "input" : "output")); return true; } @@ -170,14 +170,21 @@ Program::ExecuteAndWait(const Path& path, case 0: { // Redirect file descriptors... if (redirects) { + // Redirect stdin if (RedirectIO(redirects[0], 0, ErrMsg)) { return -1; } + // Redirect stdout if (RedirectIO(redirects[1], 1, ErrMsg)) { return -1; } if (redirects[1] && redirects[2] && - *(redirects[1]) != *(redirects[2])) { + *(redirects[1]) == *(redirects[2])) { + // If stdout and stderr should go to the same place, redirect stderr + // to the FD already open for stdout. + if (-1 == dup2(1,2)) { + MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout"); + return -1; + } + } else { + // Just redirect stderr if (RedirectIO(redirects[2], 2, ErrMsg)) { return -1; } - } else if (-1 == dup2(1,2)) { - MakeErrMsg(ErrMsg, "Can't redirect"); - return -1; } }