Index: trunk/FACT++/src/fitsdump.cc
===================================================================
--- trunk/FACT++/src/fitsdump.cc	(revision 18489)
+++ trunk/FACT++/src/fitsdump.cc	(revision 18490)
@@ -85,8 +85,8 @@
 
     ///Display the selected columns values VS time
-    void Dump(ofstream &, const vector<string> &, const vector<MyColumn> &, const string &, size_t, size_t, const string &);
-    void DumpRoot(ofstream &, const vector<string> &, const string &, size_t, size_t, const string &);
-    void DumpMinMax(ofstream &, const vector<MyColumn> &, size_t, size_t, bool);
-    void DumpStats(ofstream &, const vector<MyColumn> &, const string &, size_t, size_t);
+    void Dump(ostream &, const vector<string> &, const vector<MyColumn> &, const string &, size_t, size_t, const string &);
+    void DumpRoot(ostream &, const vector<string> &, const string &, size_t, size_t, const string &);
+    void DumpMinMax(ostream &, const vector<MyColumn> &, size_t, size_t, bool);
+    void DumpStats(ostream &, const vector<MyColumn> &, const string &, size_t, size_t);
 
 public:
@@ -177,9 +177,16 @@
 void FitsDumper::ListHeader(const string& filename)
 {
-    ofstream fout(filename=="-"?"/dev/stdout":filename);
-    if (!fout)
-    {
-        cerr << "Cannot open output stream " << filename << ": " << strerror(errno) << endl;
-        return;
+    ostream fout(cout.rdbuf());
+
+    ofstream sout;
+    if (filename!="-")
+    {
+        sout.open(filename);
+        if (!sout)
+        {
+            cerr << "Cannot open output stream " << filename << ": " << strerror(errno) << endl;
+            return;
+        }
+        fout.rdbuf(sout.rdbuf());
     }
 
@@ -401,5 +408,5 @@
 //! Perform the actual dump, based on the current parameters
 //
-void FitsDumper::Dump(ofstream &fout, const vector<string> &format, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit, const string &filename)
+void FitsDumper::Dump(ostream &fout, const vector<string> &format, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit, const string &filename)
 {
     const fits::Table::Keys &fKeyMap = GetKeys();
@@ -625,5 +632,5 @@
 }
 
-void FitsDumper::DumpRoot(ofstream &fout, const vector<string> &cols, const string &filter, size_t first, size_t limit, const string &filename)
+void FitsDumper::DumpRoot(ostream &fout, const vector<string> &cols, const string &filter, size_t first, size_t limit, const string &filename)
 {
 #ifdef HAVE_ROOT
@@ -715,5 +722,5 @@
 }
 
-void FitsDumper::DumpMinMax(ofstream &fout, const vector<MyColumn> &cols, size_t first, size_t limit, bool fNoZeroPlease)
+void FitsDumper::DumpMinMax(ostream &fout, const vector<MyColumn> &cols, size_t first, size_t limit, bool fNoZeroPlease)
 {
     vector<minMaxStruct> statData(cols.size());
@@ -789,5 +796,5 @@
 
 template<typename T>
-void displayStats(vector<char> &array, ofstream& out)
+void displayStats(vector<char> &array, ostream& out)
 {
     const size_t numElems = array.size()/sizeof(T);
@@ -829,5 +836,5 @@
 }
 
-void FitsDumper::DumpStats(ofstream &fout, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit)
+void FitsDumper::DumpStats(ostream &fout, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit)
 {
 #ifdef HAVE_ROOT
@@ -981,10 +988,18 @@
     const string filename = conf.Get<string>("outfile");
 
-    ofstream fout(filename=="-"?"/dev/stdout":filename);
-    if (!fout)
-    {
-        cerr << "Cannot open output stream " << filename << ": " << strerror(errno) << endl;
-        return false;
-    }
+    ostream fout(cout.rdbuf());
+
+    ofstream sout;
+    if (filename!="-")
+    {
+        sout.open(filename);
+        if (!sout)
+        {
+            cerr << "Cannot open output stream " << filename << ": " << strerror(errno) << endl;
+            return false;
+        }
+        fout.rdbuf(sout.rdbuf());
+    }
+
     fout.precision(conf.Get<int>("precision"));
     if (conf.Get<bool>("fixed"))
