Thread: libpq and unwanted stderr output

libpq and unwanted stderr output

From
Steve Crawford
Date:
I have some C programs which use libpq and I do not want them to write
output to the screen (unless, of course, I direct them to do so).
When I use libpq I get unwanted messaged dumped to stderr.

Example (stripped of all error-checking, etc.):

#include "/usr/include/pgsql/libpq-fe.h"

int main ()
{
  PGconn *conn;
  PGresult *res;

  conn = PQconnectdb ("dbname=steve");
  res = PQexec (conn, "create table x (a text primary key, b text)");
  PQclear (res);
  PQfinish (conn);
  return 0;
}

With nary a printf in sight, the following is nonetheless written to
stderr:
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"x_pkey" for table "x"

These various programs include daemons, backgrounded processes and
user processes (data input and query screens). In all cases these
messages are causing problems. How do I disable this behaviour?

Cheers,
Steve


Re: libpq and unwanted stderr output

From
Martijn van Oosterhout
Date:
On Fri, Aug 19, 2005 at 10:16:14AM -0700, Steve Crawford wrote:
> I have some C programs which use libpq and I do not want them to write
> output to the screen (unless, of course, I direct them to do so).
> When I use libpq I get unwanted messaged dumped to stderr.

I think you want these:

extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
                                        PQnoticeReceiver proc,
                                        void *arg);
extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
                                         PQnoticeProcessor proc,
                                         void *arg);

Not sure about the difference between the two, but just supressing them
should be easy.
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment