pg_dump output goes to stderr, not stdout?!?
pg_dump output goes to stderr, not stdout?!?
От:
"Damian C" <jamianb@gmail.com>
Дата:
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 .. 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 The output of the process is then written to the console so the output is like .. pg_dump: reading schemas pg_dump: reading user-defined functions pg_dump: reading user-defined types pg_dump: reading procedural languages ... etc etc etc .... 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) ... 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 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
Re: pg_dump output goes to stderr, not stdout?!?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Damian C" writes: > QuestionOne: Should this output go to sdout, and NOT to stderr??? No, because what normally goes to stdout is the dump data proper. Commentary has to be sent to stderr to keep it separate. As a general rule I don't think programs should have to read other programs' stderr output at all --- certainly not for "did it work or not" questions. What you ought to be doing is looking at pg_dump's process exit code to find out whether it had a problem or not. As for whether it's worth logging the stderr output for human inspection: probably, but don't use -v. -v is *intended* to create a lot of normally-useless chatter. regards, tom lane
Re: pg_dump output goes to stderr, not stdout?!?
От:
"Damian C" <jamianb@gmail.com>
Дата:
Tom, Very clear and dare I say obvious!! I do check the process exit code already, so I'll ignore stderr and stdout commentary, and use the exit code to track success, or reasons for failure. Many thanks, -Damian. On 8/21/06, Tom Lane wrote: > "Damian C" writes: > > QuestionOne: Should this output go to sdout, and NOT to stderr??? > > No, because what normally goes to stdout is the dump data proper. > Commentary has to be sent to stderr to keep it separate. > > As a general rule I don't think programs should have to read other > programs' stderr output at all --- certainly not for "did it work or > not" questions. What you ought to be doing is looking at pg_dump's > process exit code to find out whether it had a problem or not. > > As for whether it's worth logging the stderr output for human > inspection: probably, but don't use -v. -v is *intended* to > create a lot of normally-useless chatter. > > regards, tom lane >