I need to run external tool from within my Perl code. This command works for a pretty long time, prints almost nothing to STDOUT but creates a log file.
I would like to run it and in parallel read and process its log file. How can I do it in Perl?
Thanks in advance.
If you use something like File::Tail to read the log file, then you can do a simple
forkandexecto run the external command. Something like the following should work:If there are problems running the child process, the exit return code will be in the special variable
$?; see the documentation forwaitfor more information.Also, if the logging output does not provide a clue for when to stop tailing the file, you can install a handler in
$SIG{CHLD}which will catch the child process’s termination signal and allow you to break out of the loop.