pg_dump output goes to stderr, not stdout?!?

From: "Damian C" <jamianb(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: pg_dump output goes to stderr, not stdout?!?
Date: 2006-08-21 01:15:10
Message-ID: 2bbc8f530608201815k6c4ab6e7x175aa407fc541138@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello,

Apologies - this post is a bit long - but the gist is this...
1. pg_dump appears to send its output to stderr.
2. I suspect it should go to stdout.

(using PG8.1.3 on WinXP with Java/Hibernate)

I am a Java developer, and we are successfully building a distributed
desktop application for a small office setting using Postgress as our
data repository. Our SQL & Postgres skills are mediocre, but as most
things are hidden behind Hibernate ORM this has not been an issue.

Currently I am adding the capability for the database to be
automatically backed up. Manually this could be done using pgAdminIII
or perhaps a command line console using parameters such as ..
<snip>
C:\Program Files\PostgreSQL\8.1\bin\pg_dump.exe -i -h localhost -p
5432 -U pgsuperuser -F c -b -v -f "C:\dummy.backup" devdb
</snip>

The output of the process is then written to the console so the output
is like ..
<snip>
pg_dump: reading schemas
pg_dump: reading user-defined functions
pg_dump: reading user-defined types
pg_dump: reading procedural languages
... etc etc etc ....
</snip>

We have automated this in our Java application using ProcessBuilder
(to run pg_dump), and we can successfully restore the backup we
automatically create. So at this stage all appears good.

HOWEVER, it appears that this ouput is being directed to stderr, not stdout.

My original intention was to log all "stderr" output (assuming it
signified a real problem), and ignore all "stdout" output (assuming
all was well). If all output goes to stderr I cannot differentiate as
easily.

QuestionOne: Should this output go to sdout, and NOT to stderr???

So why do I think it goes to stderr? .....

To run a program like pg_dump from within Java you would typically use
ProcessBuilder. So the code could be like this (simplifying for
clarity) ...
<snip>
ProcessBuilder pb = new ProcessBuilder(cmds); // adds all the commands via cmds
Process process = pb.start(); // kick it off
StreamGobbler errorStream = new
StreamGobbler(process.getErrorStream()); // error
StreamGobbler stdStream = new StreamGobbler(process.getInputStream()); // std
</snip>

So you can see that we pick up the two separate Streams (stderr &
stdout) that collect the output from the process. When I look at those
I find that pg_dump has sent all output to errorStream.

Can anyone guide me? The options appear to be ..
1. I have gone mad.
2. My own SNAFU.
3. pg_dump is correct to send its output to stderr.
4. pg_dump bug - it should go to stdout, not stderr.
5. Java bug (I doubt it - process.getErrorStream() is basic stuff)
6. Other

Any guidance is appreciated.

Thanks,
-Damian

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2006-08-21 01:23:36 Re: pg_dump output goes to stderr, not stdout?!?
Previous Message ben sewell 2006-08-20 16:13:22 Re: Function error- A column definition list is required for functions returning "record"