From 1ffc5fd9e578ce5a9c58d04ae7f909cc2241d0f4 Mon Sep 17 00:00:00 2001 From: Brandon Diamond Date: Fri, 28 Oct 2011 16:28:25 -0400 Subject: [PATCH] CS-1535: Avoid writing to stderr unless dumping to stdout --- tools/dump.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/dump.cpp b/tools/dump.cpp index e02d725196d..626c2cc6ff9 100644 --- a/tools/dump.cpp +++ b/tools/dump.cpp @@ -37,7 +37,7 @@ class Dump : public Tool { FILE* _f; }; public: - Dump() : Tool( "dump" , ALL , "*" , "*" , false ) { + Dump() : Tool( "dump" , ALL , "*" , "*" , true ) { add_options() ("out,o", po::value()->default_value("dump"), "output directory or \"-\" for stdout") ("query,q", po::value() , "json query" ) @@ -47,6 +47,15 @@ public: ; } + virtual void preSetup() { + string out = getParam("out"); + if ( out == "-" ) { + // write output to standard error to avoid mangling output + // must happen early to avoid sending junk to stdout + useStandardOutput(false); + } + } + virtual void printExtraHelp(ostream& out) { out << "Export MongoDB data to BSON files.\n" << endl; }