2

I ran across this post: How can I retain the console input in mplayer when reading from stdin?

But the answer there doesn't work for me.

I'm running the following command:

ls -l | grep -e mp3 -e wav | awk '{i=index(0,ドル9ドル); 0ドル=substr(0,ドルi); printf "./"0ドル"\n"}' | grep " " | mplayer -playlist -

and this works fine. (minus controls)

I try this: (as proposed in the above question)

ls -l | grep -e mp3 -e wav | awk '{i=index(0,ドル9ドル); 0ドル=substr(0,ドルi); printf "./"0ドル"\n"}' | grep " " | mplayer -playlist /dev/fd/3 3<&0 </dev/tty

and it gives me this:

Playing /dev/fd/./Pink Floyd - Another Brick in the Wall.mp3.
File not found: '/dev/fd/./Pink Floyd - Another Brick in the Wall.mp3'
Failed to open /dev/fd/./Pink Floyd - Another Brick in the Wall.mp3.

can someone explain what I am doing wrong (and how to fix it?)

Currently running ubuntu 12.10 using sh.

2 Answers 2

2

It's just that your file paths are relative, and mplayer seems to interpret that as relative to the playlist's location (and not your working directory or whatever). For a zeroth approximation, you can replace "./" with your current directory, but what I'd find easier is to use

find "$(pwd)" -maxdepth 1 -name \*.mp3 -o -name \*.wav | mplayer -playlist /dev/fd/3 3<&0 0</dev/tty

(So your ls,grep,awk is replaced by this find. Admittedly, I've not double-checked completely if it is entirely equivalent. Removing the -maxdepth would make it recurse into subdirectories, which might be what you want anyway? man find is your friend here.)

answered Nov 9, 2012 at 7:38
1
  • Worked great for me. Was not aware of $(pwd) though, so thanks! It's a wonder how you learn something new about linux every day :P Commented Nov 9, 2012 at 19:55
2

mplayer thinks relative paths in the playlist are relative to the directory where the playlist is. Try using absolute paths; change your awk script to something like

awk -v dir="$(pwd)" '{ ... ; printf dir "/" 0ドル "\n" }'
answered Nov 9, 2012 at 7:44
1
  • Thanks for the awk alternative. I think that using one "find" command would be more efficient than using a ls, grep, and awk combined (plus it gives for recursive searching). Commented Nov 9, 2012 at 19:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.