zip and pipe
A little job I had to do today was to write a script (unix) to zip a file before transmitting it to a Windows system. No problem, we have zip installed…
zip file.zip file.txt
Then they decided that it was in ASCII Latin1 and they wanted it in UTF-8. Again, no problem
iconv -f ISO-8859-1 -t UTF-8 file.txt | zip file.zip -
The snag is that zip includes not only the compressed file in the output, but also headers giving details of the file name etc. In the case above the input comes from a pipe and there is no file name so it creates an entry called - (just a hyphen) which is not very useful. The unix unzip command has an option to get around this.
unzip -p file.zip > file.utf8
or you can use funzip if your implementation includes it.
funzip file.zip > file.utf8
I have no idea what they can do on Windows. I may have to do it the slow way and create an intermediate file with all the housekeeping, security and management that involves
Exercise for the reader: If you just unzip file.zip from above it creates a file called -. How do you do anything with it?









Webmaster
Hi
I just had the same problem. What you need to do is use mkfifo or mknod to create a named pipe whose name is the one you want in your zip archive.
so
# create a pipe
mkfifo file.txt
# start up zip in the background which reads from the pipe
zip archive.zip file.txt &
# run your program
a_program.exe > file.txt
Thanks very much Mark. I don’t think that I have ever used mkfifo before in 20 years of working with unix. It should be noted that you need to add a “fg” command to the end of your commands or some other method to terminate the background process. We eventually solved the problem a different way but that would have worked.
The actual problem I posed was how to deal with the file called - once you have managed to create it.