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

Dear Monks, Here is my problem today. I am running a perl file in an apache server in a browser. Now when I call this file remotely (e.g. 122.34.5.3/cgi-bin/index.pl) it should play a file on my linux server. i have put the following code in the perl file: exec(mplayer /test.mp3); but it seems to print some text on the screen instead. i want it to play the file on the server. please help. thankyou.

Replies are listed 'Best First'.
Re: Perl Exec
by Perlbotics (Archbishop) on Oct 19, 2008 at 17:58 UTC

    You might want ...

    • to tell what the program displayed. Your webservers log file should hold further information.
    • use system instead of exec, since exec terminates the current process (might work, but the HTTP response might be incomplete; simple webservers might terminate).
    • use an absolute path for mplayer and options to terminate the player when done.
    • check permissions: does your webserver has access to the audio device and to the mp3-file?
    • /test.mp3 is located at your computers filesystems root-dir, not your webservers root-dir (where /cgi-bin/... starts). You might use an absolute (filesystem) path too.
    • consider security issues (e.g. restrict access to 127.0.0.1., check user input).
    • ...