Results 1 to 4 of 4
I would like to create a thread and pipe all "printf" to a new terminal (kconsole or xterm) mean time the main program stays in different kconsole for more user ...
- 06-11-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 6
printf to different console
I would like to create a thread and pipe all "printf" to a new terminal (kconsole or xterm) mean time the main program stays in different kconsole for more user inputs. Can you please help where I should start??
Thanks in advance.
- 06-11-2008 #2
Is it necessary that this be a thread, or can it be a different process?
And which programming language are you using?--
Bill
Old age and treachery will overcome youth and skill.
- 06-11-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 6
I am using C code. I would like to do it w/ threads.
If not, then I will try process.
Any answer will be appreciated!!
- 06-11-2008 #4
I presume you want to use printf() calls as they are now, without modifying them.
Try this:
- In the main program, before firing off the subsidiary process, create a file with a particular name, and make sure it's empty. I'll call this file fred.
- After the file has been created, the main program should do something like this:
Code:fork_result=fork(); if(fork_result==-1) { /* error handling goes here */ } if(fork_result==0) { system("xterm -e tail -f fred"); exit(0); } - In the subsidiary process, do something like this:
Code:if(freopen(stdout,"fred","w")==NULL) { /* error handling goes here */ }
The reason this can't be done with threads is that the freopen() will affect standard output for all threads, not just that one.
Fair warning: I have not tested this concept.
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote