简体   繁体   中英

How do I execute an external program from Perl and have the perl script continue

I am running a perl script from a cron job on Ubuntu. As part of the script it needs to execute an external program and not wait for the program to complete and also continue executing the script. I have tried the following but as near as I can tell it is not executing the program and also seams to not continue the script.

exec("/usr/bin/dotnet /usr/local/myprogram/myprogram.dll arg1, arg2, moreargs")
    or print STDERR "Couldn't exec myprogram";

So:

my $child_pid = fork();
die "Couldn't fork" unless defined $child_pid;
if (! $child_pid) {
  exec '/usr/bin/dotnet', '/usr/local/myprogram/myprogram.dll', 'arg1', 'arg2', 'moreargs';
  die "Couldn't exec myprogram: $!";
}

# rest of script

wait();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM