'cat' Write Error Due to Cygwin Pipe Problem

Recently, while porting a shell script from Linux to Cygwin, I encountered an error due to Cygwin pipe problem. The error producted while executing the following commmand line:

cat a.file b.file | head -c 1M > c.file

And the error said:

cat: write error: No space left on device

According the error message, I checked the file size of a.file and b.file:

> ls -l a.file b.file
-rwx------+ 1 yestyle mkpasswd 841920 May 5 16:39 a.file
-rwx------+ 1 yestyle mkpasswd 7340032 May 4 11:16 b.file

And the disk usage information:

> df -h
Filesystem Size Used Avail Use% Mounted on
D:/cygwin/bin 60G 49G 12G 82% /usr/bin
D:/cygwin/lib 60G 49G 12G 82% /usr/lib
D:/cygwin 60G 49G 12G 82% /
C: 30G 28G 1.6G 95% /cygdrive/c
D: 60G 49G 12G 82% /cygdrive/d
E: 61G 44G 17G 74% /cygdrive/e

As you can see, the available space of disk is fairly enough for the concatenated size of a.file and b.file, which is about 7.8MB.

So the limitation of pipe buffer size became suspect, and I modified the command line as following (using a temporary file instead of pipe):

cat a.file b.file > tmp.file
head -c 1M tmp.file > c.file

And it worked! I couldn't find the accurate pipe buffer size of Cygwin (and the reference source) after Googling for a while, but it just worked.

PS: My environment information:

  • Cygwin: 1.7.18(0.263/5/3)
  • Windows: XP version 5.1 (2600.xpsp_sp3_qfe.130704-0421: Service Pack 3)

你可能感兴趣的:('cat' Write Error Due to Cygwin Pipe Problem)