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

First time here on PerlMOnks... hoping someone can help me out...

Aight I'll make this short and sweet, what I would like to do is make a web based interface to mpg321 on FreeBSD using mod_perl.

I WILL NOT be streaming the mp3s to another program, I just basically want to make a web-based frontend to mpg321.

I think I have everything figured out EXCEPT how to RE-establish communication with mpg321 AFTER a script has finished running and I run it again. For instance, we run the Perl script once, it runs and starts mpg321, and tell is to play a song. The script ends. Now,I want to run it again and tell mpg321 to STOP playing hte song, or to play another song, or pause, or etc., etc.

Problem is, I don't know how to re-establish communication with that process to be able to send input to it THE SECOND TIME THE SCRIPT RUNS. Does anyone know how?
  • Comment on Perl/CGI Question - mod_perl IPC / Unix / mpg321...

Replies are listed 'Best First'.
Re: Perl/CGI Question - mod_perl IPC / Unix / mpg321...
by perrin (Chancellor) on May 19, 2003 at 19:05 UTC
      I was also kinda hoping that I could get a general answer to my question... I'd prefer to learn to do it myself and not use some pre-built script... But I'll check those out too thanks!
        You could always read the code and see how the modules do it if you want to learn it for yourself. Don't be afraid to use modules if available. :)

        I'm sure they also appreciate if you combine your efforts and submit any improvements regarding versatility and such to the existing code base as well.
        Well, you have to turn mpg123 into a daemon and communicate with it through IPC. These modules demonstrate different ways to do that.
        If you want a general answer, you can use named pipes, created by the mknod command. They solve the following problem: one can use pipes to divert the standard output of a program to the standard input of another one, but sometimes, one may want several programs (or several copies of the same program) to write to the standard input of a single program, one after the other. A named pipe look like a file, several programs may write to it, and a program reading from it would get the stream of data as if it came from a single file. But this Unix-specific mechanism is quite old---I wouldn't really advise using it for serious stuff.