prekursor has asked for the wisdom of the Perl Monks concerning the following question:

Here is my problem: I wrote little tk application that launches various radio stations, however when i use system call to launch my mplayer, perl script waits for it to complete, therefore I loose control of my perl script. I want to be able to launch mplayer, and continue executing rest of the perl code that is after system call without waiting for mplayer to finish. How do I accomplish that? thank you

Replies are listed 'Best First'.
Re: launching application from perl
by kyle (Abbot) on Mar 20, 2008 at 17:39 UTC

    See fork and exec.

    my $cmd = 'mplayer command line'; my $child_pid = fork(); die "Can't fork: $!" if ! defined $child_pid; if ( ! $child_pid ) { exec $cmd or die "Can't exec '$cmd': $!"; }

    At that point, you have to remember to wait for the child at some point (with a $SIG{CHLD} handler). The documentation for fork discusses this.

Re: launching application from perl
by pc88mxer (Vicar) on Mar 20, 2008 at 18:03 UTC
    The simpler:
    system("mplayer &");
    might work (it works for xine). It works for a lot of GUI apps which don't read from stdin, but doesn't work in general. Also, you won't get the pid of the mplayer process, but perhaps that's not a concern.
Re: launching application from perl
by halfcountplus (Hermit) on Mar 21, 2008 at 00:17 UTC
    YOU REALLY ARE GOING TO HAVE TO INCLUDE THE LITERAL CODE YOU USED TO TRY TO DO WHAT YOU CLAIM TO HAVE FAILED AT. "System call" could mean a few things.

    I've ran mpg123 thru Tk and there are issues, but look! no code here either ;)
      this worked : system("mplayer &"); specifically ampersand. Thanks guys