Permalink
Browse files

CS-1535: Avoid writing to stderr unless dumping to stdout

  • Loading branch information...
1 parent 8a79e63 commit 1ffc5fd9e578ce5a9c58d04ae7f909cc2241d0f4 Brandon Diamond committed Oct 28, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 tools/dump.cpp
View
@@ -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<string>()->default_value("dump"), "output directory or \"-\" for stdout")
("query,q", po::value<string>() , "json query" )
@@ -47,6 +47,15 @@ class Dump : public Tool {
;
}
+ 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;
}

0 comments on commit 1ffc5fd

Please sign in to comment.