Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|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. – BinaryMisfit Jan 18 '11 at 6:42

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 -
share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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