Need to dump an MPEG2 file in a loop, either to stdout or a named pipe.

This works:

$ { while : ; do cat myLoop.mpg; done; } | vlc -

This works on a text file containing "1234\n":

$ mkfifo myPipe
$ cat test.txt > myPipe & < myPipe tee -a myPipe | cat -

(it correctly loops, outputting "1234" on every line). Why does the following NOT work?

$ cat myLoop.mpg > myPipe & < myPipe tee -a myPipe | vlc myPipe

I'm primarily interested in re-writing the first statement to remove the improper "cat myLoop.mpg" statement. Will be inputting into VLC, or into FFMPEG and then piped into VLC.

link|improve this question
Please review the FAQ. This is not a forum, please use comments to reply to others, edits to update your questions and answer only for... well answers. – Diago Jan 18 '11 at 6:42
feedback

1 Answer

The last one probably doesn't work because you've got vlc reading from the named pipe instead of stdin.

See if this works:

cat myLoop.mpg > myPipe & < myPipe tee -a myPipe | vlc -

What's wrong with your first example? The curly braces aren't necessary, by the way:

while :; do cat myLoop.mpg; done | vlc -
link|improve this answer
Good catch. That was a typo in the post, not the problem, sadly. As you said, it should have been: cat myLoop.mpg > myPipe & < myPipe tee -a myPipe | vlc - I was under the impression cat was for concatenating multiple files and using it to output a single file was inefficient/hackish. Reading/writting the same pipe + tee may not be any better. Question still stands if anyone has suggestions/alternatives. – Matt Cook Jan 18 '11 at 6:40
@Matt: It's a useless use of cat when you use it to pass a file to another utility via a pipe when the utility will accept a filename as an argument cat file | grep foo vs. grep foo file. It's also unnecessary to use cat in Bash to read a file into a variable: var=$(cat file) vs. var=$(<file) or to feed it into a loop cat file | while vs. while ... done < file. However, sometimes cat is exactly right. I think my revision of your first example is one of those times. It's much more straightforward than the named pipe version. – Dennis Williamson Jan 18 '11 at 8:23
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.