tags:

views:

14

answers:

1

I am writing a console application which is using some library in which (DEBUG) prints are enabled. In my main() application I am taking inputs from user. I want this user input to be separate from my library prints. I cant disable library debug prints. (The problem is library has lots of continuous prints over which it is difficult to take user input. Can I do something like creating a new tty for taking user inputs. )

A: 

dup2(2,3p) lets you duplicate an existing file descriptor (such as the one you just opened on /dev/null) onto another existing file descriptor (such as FD2, stderr). So, open /dev/null for writing and clobber stderr with it.

Don't forget to add an option to disable this though, in case you need to debug.

Ignacio Vazquez-Abrams