Skip to content

Commit

Permalink
CS-1535: Avoid writing to stderr unless dumping to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Diamond committed Feb 15, 2012
1 parent 24e1f0b commit f96f1c7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tools/dump.cpp
Expand Up @@ -37,7 +37,7 @@ class Dump : public Tool {
FILE* _f; FILE* _f;
}; };
public: public:
Dump() : Tool( "dump" , ALL , "*" , "*" , false ) { Dump() : Tool( "dump" , ALL , "*" , "*" , true ) {
add_options() add_options()
("out,o", po::value<string>()->default_value("dump"), "output directory or \"-\" for stdout") ("out,o", po::value<string>()->default_value("dump"), "output directory or \"-\" for stdout")
("query,q", po::value<string>() , "json query" ) ("query,q", po::value<string>() , "json query" )
Expand All @@ -47,6 +47,19 @@ 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;
}

// This is a functor that writes a BSONObj to a file // This is a functor that writes a BSONObj to a file
struct Writer { struct Writer {
Writer(FILE* out, ProgressMeter* m) :_out(out), _m(m) {} Writer(FILE* out, ProgressMeter* m) :_out(out), _m(m) {}
Expand Down

0 comments on commit f96f1c7

Please sign in to comment.