Gordon Gudmundson
Gordon Gudmundson

Reputation: 37

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";

Upvotes: 0

Views: 650

Answers (1)

ruakh
ruakh

Reputation: 183241

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

Related Questions