comp.lang.c
[Top] [All Lists]

Temporarily close stdout?

Subject: Temporarily close stdout?
From: Joakim Hove
Date: Wed, 30 Apr 2008 05:36:02 -0700 PDT
Newsgroups: comp.lang.c

[ This question is about closing/reopening/... of stdout - I hope that
is on topic?]

Hello,

I have written a program in C; this programs uses an external
proprietary library. When calling a certain function in the external
library, the particular function writes a message to stdout. I am not
particularly interested in this message, and would like to silence it
- however I do not know how to do it. (I stdout and stderr my self, so
just redirecting into oblivion is not an option).

An excerpt of the code looks like this:


   ....
  /* Offending call in external library. */
  job_nr = lsb_submit( &request , &reply);


When this code is run - the offending function (or some function it
calls), writes
"Job <123456> is submitted to queue <common>"

An information I am completely uninterested in sending stdout. So I
wondered if it would be possible to do something like this:


   ....
   /* Temporarily close stdout: */
   fclose(stdout);
   job_nr = lsb_submit( &request , &reply );
   /* Reopen stdout */
   stdout = fdopen(1 , "a");

I have tried the code listed above - but the fdopen() failed with "Bad
file descriptor" (I had not expected it to succeed ...). Anyway - any
suggestions would be highly appreciated.


Joakim



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy