In perl, after fork()ing I can redirect a child’s stdout to a file like so
open STDOUT,">",$filename or die $!
I’m wondering if there is a way of “copying it”, keeping the stdout on the parent’s stdout but also copying to a specified file. It should happen in a way that would not require any buffering and the user would see the console output in real time. This would sort of be like the unix tee. But ideally the solution would not involve any third party libraries.
In the child, execute
If you don’t want to use
teefor some reason, you could use a poor man’s version by forking another child viaopen STDOUT, "|-"and doing the duplication in the grandchild:Sample run: