Reputation: 37
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";
Upvotes: 0
Views: 650
Reputation: 183241
exec
. (See https://perldoc.perl.org/functions/exec.html.)fork
(see https://perldoc.perl.org/functions/fork.html) so that you have two separate processes running in parallel (one running the program, one running the rest of the script).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();
Upvotes: 2