io redirection - Perl, redirect stdout but keep on parent -


I can

  open STDOUT, "& gt; $$$$$$ or $$ dies! I'm wondering if there is a way to "copy it", copy stdout to a specified file even while keeping the stdout on the parent stdout. It should be that no buffering is required and users will see the console output in real time. It will be like Unix  tee  but ideally the solutions will not include any third party libraries. 

Execute in the child

  open STDOUT, "| - "," T ", $ output or die" $ 0: Failed to start TE: $! ";  

If you do not want to use tee for some reason, then you should ask the Other Version can be used by open STDOUT, "| - -" and duplication in grandparent:

  #! Use / usr / bin / perl warnings; Strict use; My $ pid = fork; "$ 0: fork: $!" Unless defined as $ pid; If ($ pid) {waitpid $ pid, 0; } And {my $ pid = open STDOUT, "| -"; "$ 0: fork: $!" Unless defined as $ pid; Choose STDOUT; $ | = 1; Disable #StDOUT buffering if ($ pid) {print "Hiya! \ N"; "How echo" system is; Turn OFF STDOUT or "$ 0: OFF: $!" give a warning; Exit 0; } And my $ position; while ($ position = SSDIS, my $ data, 8192) and $ $: Open: $! {Syswrite $ fh, $ data and print $ data or dies "$ 0: output failed: $!";); } "$ 0: sysread: $!" Not defined until $ position; About $ FH or "$ 0: Close: $!" give a warning; Exit 0; }}  

Sample run:

 $ ./owntee Hiia! Howdy Cats Other Output Hiia! Howdy 

Comments