如何在Perl中运行脚本而不是等待它?

Laz*_*zer 7 perl cross-platform platform-independent

我在Perl中有一个系统调用,如下所示:

system('/path/to/utility >> /redirect/to/log file');
Run Code Online (Sandbox Code Playgroud)

但这等待utility完成.我只是想触发这个并让Perl脚本完成,无论utility调用是否结束.

我怎样才能做到这一点?

我尝试将线路更改为

system('/path/to/utility >> /redirect/to/log file &');
Run Code Online (Sandbox Code Playgroud)

但是这种语法仍然等待在Windows上完成调用.我需要让它在Linux和Windows上运行.

ike*_*ami 7

if ($^O eq 'MSWin32') {
   system('start "" \\path\\to\\utility >> \\redirect\\to\\log_file');
} else {
   system('/path/to/utility >> /redirect/to/log_file &');
}
Run Code Online (Sandbox Code Playgroud)

要么

if ($^O eq 'MSWin32') {
   system(1, '\\path\\to\\utility >> \\redirect\\to\\log_file');
} else {
   system('/path/to/utility >> /redirect/to/log_file &');
}
Run Code Online (Sandbox Code Playgroud)