Using fifos and links to control remote process from a webpage (Linux)

984 views Asked by At

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,

3

There are 3 answers

0
vicaba On BEST ANSWER

mpg123 has it's own --fifo option

0
1337 on Tuesdays On

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
jfs On
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.