ActivePerl: exec/system call in background

System() is tricky in a Windows environment.

There is usually no way to quickly launch a program from Perl, then continue with your code right away while the program is (still) running. Instead, Your Perl script will stop as soon as you start an external program.

This is because system() waits for the child process (your external program) to exit before going on. On Linux command line, this makes perfect sense, but what if you need to run a Windows program with a GUI in the background to work with?

#!C:/Perl/bin/perl

#definition of the program to launch in background
$gamelaunch='D:\Games\HoMM\HoMM.exe';
#preparation of our external "Perl.exe" call.
$gamelaunch='perl -e "exec(\''.$gamelaunch.'\')"';

print "Starting Program\n";
system($gamelaunch);
#actual program start
#normally the script would be locked up now
print "It's magic";


sleep(30);

Source: (2006-09-15 16:14:57)