Temporarily close stdout?



[ 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


.



Relevant Pages

  • printing and opening a pipe
    ... I'm calling a library function that prsnts something to stdout. ... save to string. ...
    (comp.unix.programmer)
  • Re: Unit test an output with puts
    ... back from calling util_capture that hold the contents of $stdout and ... $stderr in the block: ... console during the test? ...
    (comp.lang.ruby)
  • Re: Newbie external script return question.
    ... So, as I think I understand it now, the calling program is "STDOUT" (so to ... speak) to the called program. ... program is no different than calling some system utility like PING and ...
    (comp.lang.perl)