Shell – Pipe output from program which only outputs to a file

linuxpipeshell

pico2wave only supports outputting to a file (edit: with extension .wav). How can I coerce the output into a pipe for aplay, without cleaning up any named pipes or temporary files or a wrapper script?

Ie, pico2wave -w tmp.wav "test" && aplay tmp.wav && rm tmp.wav creates a temporary file, and is thus not what I'm looking for as a solution.

Best Answer

A note on the general solution: to many programs which require a filename you can give the path /dev/stdout (a link to /proc/self/fd/1, assuming said files exist) and they will happily send their output to stdout. One may also use process substitution in bash with cat, ie foo -f >(cat) args | bar (thanks, g-man).

Because pico2wave checks the file extension, a possible solution is to symlink /dev/stdout to a path with the appropriate extension, ideally somewhere such as /var/local/. This does create an extra file, but not per process: ln -s /dev/stdout /var/local/pico2wave.wav, then pico2wave -w /var/local/pico2wave.wav "test" | aplay works.

Related Question