Alam
Alam

Reputation: 1596

How to direct program prints to seprate window(shell/tty)

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. )

Upvotes: 1

Views: 178

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798546

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.

Upvotes: 1

Related Questions