Sunday, February 5, 2012

tar for windows, windows cannot fork

So, I wanted to duplicate my trick of using os.system calls in python to tar, gzip, and delete some files on my Windows filesystem. Leaving aside how completely ignorant this idea was since both things can be done from within python and platform independently, the story of the problem that I encountered and its solution is worth remembering.

Since I totally use the "GNU for windows" utilities to do things in windows when I don't want to step into Cygwin, I just downloaded GNUWin tar and tried it out:

http://gnuwin32.sourceforge.net/packages/gtar.htm
http://gnuwin32.sourceforge.net/packages/gzip.htm
http://gnuwin32.sourceforge.net/packages/coreutils.htm

However, when I blithely fed my first tar command into it using the gzip option and wildcards, I got an error "Windows cannot fork". So sad. It turns out that it looks like the GNU tar port can't call gzip to do the -z option or something?

http://osdir.com/ml/lang.ruby.rake/2006-11/msg00014.html
http://www.worthinstalling.com/2006/06/command-line-compression-for-windows.html
http://stackoverflow.com/questions/1437875/tar-on-windows-a-list-of-files-in-c-sharp

As indicated in the first two links above, the answer is to use bsdtar, which is just a different GNU utility that's compatible with everybody else in my GNU installation folder and installs exactly the same way but with a different picture in the install window:

http://gnuwin32.sourceforge.net/packages/libarchive.htm

Beautiful.