#!/usr/bin/perl use strict; use diagnostics; use warnings; use IPC::Run qw/start/; use POSIX ":sys_wait_h"; my ($h, $pid, $result); # Play the sound file $h = start ['play','-q','/home/ra/Desktop/trek3.mp3']; # Get the process ID (there's only one) foreach my $kid (@{ $h->{KIDS} }) { $pid = $kid->{PID}; } # Wait for the sound file to stop playing, and then display a message # Option 1: scripts hangs, and then correctly displays a message # as soon as the sound file stops playing sleep 5; waitpid($pid, 0); print "finished!\n"; # Tidy up $h->signal('INT'); $h->finish;