I am trying to capture STDOUT to a file with Capture::Tiny.
To give you the bigger picture, my end-goal is to:
- run a Blender process on the command line
- capture the log to a filehandle
- watch the filehandle "grow"
- pipe the content of the filehandle to a websocket for the user to watch progress via a web page
My plan is to use Capture::Tiny, and the example provided in this thread.
However I am stuck at step 1: I can capture STDOUT and STDERR as expected like this:
use IO::File;
use Capture::Tiny qw/capture/;
$\ = "\n"; $, = "\t";
my $blender = '/home/simone/blender/blender-3.1.0-linux-x64/blender -b /home/simone/some_file.blend --python /home/simone/blender_scripts/some_script.py';
my ($stdout, $stderr, $exit) = capture {
system( $blender );
};
print join "\n", "STDOUT", $stdout =~ s/Time/Foobar/rg;
print '-' x 80;
print join "\n", "STDERR", $stderr;
print '-' x 80;
which produces the correct output but - as far as I can understand - does not let me watch it progress.
Doing this:
my $out_fh = IO::File->new("out_stdout.txt", "w+");
my $err_fh = IO::File->new("out_stderr.txt", "w+");
capture { qx/$blender/ } stdout => $out_fh, stderr => $err_fh;
leaves me with two empty files. Those are the two files I'd like to watch later.
How should I do this? is there a better (i.e.: workable) way?