I have a system call in Perl that looks like this:
system('/path/to/utility >> /redirect/to/log file');
But this waits for utility
to complete. I just want to trigger this and let the Perl script finish irrespective of whether the utility
call finished or not.
How can I do this?
I tried changing the line to
system('/path/to/utility >> /redirect/to/log file &');
but this syntax still waits for the call to finish on Windows. I need to make it work on Linux as well as Windows.
if ($^O eq 'MSWin32') {
system('start "" \\path\\to\\utility >> \\redirect\\to\\log_file');
} else {
system('/path/to/utility >> /redirect/to/log_file &');
}
or
if ($^O eq 'MSWin32') {
system(1, '\\path\\to\\utility >> \\redirect\\to\\log_file');
} else {
system('/path/to/utility >> /redirect/to/log_file &');
}
You could try looking at the fork
keyword, and launch your system command from the forked process. See the perlipc
manpage for examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With