views:

1413

answers:

3

What are the differences between pipes in Windows and Linux?

+9  A: 

One difference that I know of, is that named pipes under Linux are actual entries in the filesystem (you'll see it in a directory listing, they have a special type), whereas on Windows they are stored in some magical repository somewhere (they are all accessed via the path "\\.\pipe\".

Secondly, in Linux you can just write/read from pipes as if they were any other file, using standard file IO methods. Whereas on windows, you have to use the special 'Pipe' functions which are part of the Win32 API.

I like linux's method better, because it lets me use pipes with any app I want. Eg:

mkfifo pipe.wav
decodeMP3 song.mp3 --out pipe.wav &
encodeAVI video.mpeg pipe.wav --out video.avi

This lets me pipe the output of the MP3 decoder directly into the video decoder, instead of having to first decode the entire MP3 into a WAV file on disk. It's handy if you have a dual-core CPU, because then you are running both operations at once, for a nice speedup.

davr
+1  A: 

Under Linux (and *ix in general), "everything is a file". You can read/write/seek pipes and sockets and devices with no restrictions, insofar as those operations make sense.

Whereas Windows has a far less unified architecture for these different types of objects. Though I couldn't tell you the details, I know that buffering of pipes is considerably different between Windows and Linux, so you may run into difficulties there.

Also, one common Unix-y use of pipes is to fork() a subprocess and then communicate with it via a pipe (the parent opens one end, the child opens the other end). Under Windows, that kind of thing just isn't possible. IPC mechanisms are quite different.

Dan
+2  A: 

See also the previous thread:

What are named pipes?

Which contains my take and several other peoples'

MarkR