Changing the inherited STDOUT

Y

yosi.kal

Hi,

My program runs as a child process of a process that its STDOUT was
redirected to a file. (open STDOUT, ">$logfile").
Obviously, the child process inherits the STDOUT redirection. My
question is: if I need to write something to the real output (for
example, the terminal in unix), how can I claim back the original
STDOUT?

Thanks, Yosi
 
J

Josef Moellers

Hi,

My program runs as a child process of a process that its STDOUT was
redirected to a file. (open STDOUT, ">$logfile").
Obviously, the child process inherits the STDOUT redirection. My
question is: if I need to write something to the real output (for
example, the terminal in unix), how can I claim back the original
STDOUT?

You can't. Period.

What was your original STDOUT anyway? Maybe it had been a file from the
start, maybe it was a terminal (you might be able to open the
controlling tty "/dev/tty"), maybe it was "/dev/null" and you don't have
a controlling tty.
 
D

Daniel Fischer

(e-mail address removed)!
Obviously, the child process inherits the STDOUT redirection. My
question is: if I need to write something to the real output (for
example, the terminal in unix), how can I claim back the original
STDOUT?

Not. You can, however, write to STDERR.


Daniel
 
M

Mumia W.

Hi,

My program runs as a child process of a process that its STDOUT was
redirected to a file. (open STDOUT, ">$logfile").
Obviously, the child process inherits the STDOUT redirection. My
question is: if I need to write something to the real output (for
example, the terminal in unix), how can I claim back the original
STDOUT?

Thanks, Yosi

"Perldoc -f open" shows you how to save and restore STDOUT (and STDIN
and STDERR).
 
D

Daniel Fischer

Mumia W.!
My program runs as a child process of a process that its STDOUT was
redirected to a file. (open STDOUT, ">$logfile").
[...]

"Perldoc -f open" shows you how to save and restore STDOUT (and STDIN
and STDERR).

This would only work if the child process redirected STDOUT itself, which
from my understanding of the question, it does not.


Daniel
 
M

Mumia W.

Daniel said:
Mumia W.!
My program runs as a child process of a process that its STDOUT was
redirected to a file. (open STDOUT, ">$logfile").
[...]
"Perldoc -f open" shows you how to save and restore STDOUT (and STDIN
and STDERR).

This would only work if the child process redirected STDOUT itself, which
from my understanding of the question, it does not.


Daniel

You're right, it's too late for the child. The most portable solution is
to write to STDERR, as you said.
 
B

Brian McCauley

My program runs as a child process of a process that its STDOUT was
redirected to a file. (open STDOUT, ">$logfile").
Obviously, the child process inherits the STDOUT redirection. My
question is: if I need to write something to the real output (for
example, the terminal in unix), how can I claim back the original
STDOUT?

Well, not that this has anything to do with Perl, and it's not the
answer to the question you asked but have you heard of /dev/tty under
Unix?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,189
Messages
2,571,016
Members
47,618
Latest member
Leemorton01

Latest Threads

Top