Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

tk player with system/exec

by mce (Curate)
on Dec 20, 2002 at 14:16 UTC ( [id://221436]=perlquestion: print w/replies, xml ) Need Help??

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

Hi oh wize ones,

I have a question about perl Tk (perl 561, tk800.024).
I want to make a radio player that runs mplayer url sites from a mysql database. I have already made the framework, and I am able to do almost everything. One thing I still cannot do is this:

I open a MainWindow/TopLevel with all the possible stored radio urls from mysql. Than I click on one and this starts mplayer.To do this I launch mplayer with a fork + exec. And in the mean time, I open a new TopLevel just a button that the specific radio is playing.

Now my question: When the mplayer command exits or abords, the TopLevel button still shows running as I run mplayer with an exec, and there is no feedback to the Tk window.

How can I deal with this?

Is there a Tk module that allows one to fork a new process (with system or exec or whatever) and that shows in the mean time a window it is running, and closes the window when it is finnished. It would even be nice to have a kill method to?

I looked at Tk::IO etc.. But I have no clue how to use it.

I hope my question is clear enough.
---------------------------
Dr. Mark Ceulemans
Senior Consultant
IT Masters, Belgium

Replies are listed 'Best First'.
Re: tk player with system/exec
by pfaut (Priest) on Dec 20, 2002 at 14:28 UTC

    You need to handle SIGCHLD signals. When a child process exits, the parent gets a SIGCHLD. There, you call waitpid() to get the exit status of the child.

    This is from my own Tk based mp3 player:

    #start a new song $SIG{'CHLD'} = 'sig_child'; if ($pid = fork) { $w::main->configure( -title => "TkMP3 - $fnm" ); $w::title->configure( -text => $fnm ); } elsif (defined $pid) { exec 'kmp3player','-q','-b','256',$fnm; } else { die "Can't fork: $!\n"; } # the child exit handler sub sig_child { $wsts = waitpid($pid,WNOHANG); $sts = $?; if ($wsts == 0) { $SIG{'CHLD'} = 'sig_child'; return; } die "Child exited abnormally, exiting\n" if $sts != 0; # send notification to app to pick next song #....
    }
    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
      Thanks,

      This is the way I was thinking of doing it.

      But there is no Tk addon module that has some kind 'play' mechanisme and that handles all these signals itself, so I don't need to code it myself?
      ---------------------------
      Dr. Mark Ceulemans
      Senior Consultant
      IT Masters, Belgium

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://221436]
Approved by Tanalis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2024-04-25 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found