Linux: Add named files from pipes to the zip archive

Linux: Add named files from pipes to the zip archive … here is a solution to the problem.

Linux: Add named files from pipes to the zip archive

Is it possible to use something like this:

The command .exe | a zip >> archive .zip

Command 2.exe | zip >> archive .zip

… And get two named files in a zip archive.
If possible, this way is cleaner than using temporary files.

Solution

Create two named pipes (using mkfifo) in the new directory, pipe the output of the command to both pipes, and then zip the directory.

mkdir tmp
mkfifo tmp/1.out
mkfifo tmp/2.out
command1.exe > tmp/1.out
command2.exe > tmp/2.out
zip -FI -r tmp.zip tmp/

EDIT: Added FI flag to zip, which really makes this possible. The only caveat is that you need zip 3.0 to work. Tar:ing FIFO:s is not implemented (according to tar developers) because you need to know the file size in advance to write it to the TAR header.

Related Problems and Solutions