4

I'm using mpg123 in a linux server and I'm trying to control it through a webpage (apache), using links to send different controls.

mpg123 has the -C flag so you can send characters to it. "s" key = start/stop, "f" key = next track... and so on.

I think I can send mpg123 those keys with a fifo, changing mpg123 stdin to the fifo stdout but i don't know how to use the fifo in this case (how to make mpg123 "listen" to another stdin). What I've done is:

mkfifo myfifo
myfifo | mpg123 -C -@ musiclist.txt
And then I've created keys.txt adding some keys to the file:
echo "f" >> keys.txt
echo "s" >> keys.txt

Then:

cat keys.txt >> myfifo.fifo

This does not work. Can someone explain ow can I use fifos to pass messages to a running mpg123? I've googled it but can't find what I want.

This question seems to give me some light, but I still don't know how to make mpg123 listen to the fifo's output.

Thank you in advance,

Community
  • 1
  • 1
vicaba
  • 2,836
  • 1
  • 27
  • 45
  • If you want to provide a web-interface to a command-line program then you don't need mkfifo if it can accept input from stdin as in your case. – jfs Dec 20 '13 at 10:05
  • here's an example of how you could connect [a command-line program and web browser](http://stackoverflow.com/a/11729467/4279) – jfs Dec 20 '13 at 12:02

3 Answers3

0

What are you using to pipe myfifo?

I'll assume cat myfifo | mpg123 -C -@ musiclist.txt

cat will close after the first file piped through myfifo. Try using tail -f myfifo | ... instead to keep it open after EOF.

0
mkfifo myfifo
tail -f myfifo | mpg123 .. &
# send commands
echo .. > myfifo
sleep 5
echo .. > myfifo

tail is optional unless mpg123 exits if it receives EOF on stdin. Otherwise you could use: <myfifo mpg123 ...

& at the end (control operator to execute the command in the background) is optional if you run echo commands in another terminal.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
0

mpg123 has it's own --fifo option

vicaba
  • 2,836
  • 1
  • 27
  • 45