Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video stuck on system(1, @commands) in Perl script

I'm trying to write a Perl script that runs videos in a directory n times on Windows Media Player one after the other.

For some reason, on the 64th video playing, it gets stuck on system(1, @commands).

Right now, the command is system(1, "C:\\Program Files (x86)\\Windows Media Player\\wmplayer", $path); in the following for-loop.

for (my $i = 0; $i < $n; $i++)
{
    # do stuff

    # Play video
    system(1, "C:\\Program Files (x86)\\Windows Media Player\\wmplayer", $path);

    sleep $duration + 1;

    # do stuff
} 

I'm wondering why it keeps stopping at the 64th video (I've run this multiple times and it's always the 64th.) Maybe someone can explain system(1, @commands) better to me? All I know is that it just doesn't wait for @commands to finish before continuing the program...

Thanks a lot!

like image 282
corgichu Avatar asked Dec 15 '22 21:12

corgichu


1 Answers

You've reached the maximum number of child processes you can have running simultaneously. Reap those that have completed using waitpid.


Alternatively, if you don't care about the process's exit code, you might have better luck with

system(qq{start /b "" "c:\...\wmplayer" "$path"});
like image 172
ikegami Avatar answered Dec 23 '22 14:12

ikegami