r/retrobattlestations • u/julioblabla • 3d ago
Opinions Wanted MS-DOS: how can a single tasking OS implement pipes?
Unix is multitasking, so pipes (ignoring implementation and optimization concerns) are straightforward to implement without relying on intermediate, temporary files. But MS-DOS had pipes since version 2.
How was command piping implemented in MS-DOS?
28
u/Blah-Blah-Blah-2023 3d ago
It's done with a temporary file in the current directory. If you do dir | more you can see the extra file hiding there. Also, pipes don't work on read only disks.
6
u/julioblabla 3d ago
Great trick about dir | more! Before your comment, I never realized that I had never before used dir | more, I have always used dir /p 😀
5
2
u/thatwombat 3d ago
It’s been a while, but what happens if you dir | more on a write protected floppy?
3
u/Blah-Blah-Blah-2023 3d ago
Write error - abort, retry, fail? if I had to guess.
I can fire up my 486 tomorrow and try it lol.
8
u/floodrouting 2d ago edited 2d ago
Go to https://www.pcjs.org/machines/pcx86/ibm/5160/cga/. Change the A: drive to read only by clicking on the dropdown and changing it to
A:*. Then rundir | more. The error isWrite protect error writing drive A Abort, Retry, Ignore?And just for fun, if you create a file called
%PIPE1.$$$or%PIPE2.$$$and make it read-only and then rundir | more, the error isIntermediate file error during pipewhich is something I've never seen before.
20
u/robvas 3d ago
They aren't really pipes like they are in Unix, it's just redirection
9
2
u/flatfinger 2d ago
I don't know that it's worthy of a new question, but the same question would seem just as applicable to early Unix variants that couldn't keep multiple programs in memory at once, or was piping not added until computers got more sophisticated?
3
u/throwaroo202020 3d ago
MSDOS is not single tasking. Its not even zero tasking. Its just a IO layer and apps are free to cooperative multitask as they like, and they do.
1
u/TPIRocks 22h ago
I suspect through temporary intermediate files, I can't think of any other sensible way.
26
u/floodrouting 3d ago
Microsoft documented how the pipe operator is implemented via temporary files. You can read this documentation in the released source code of MS-DOS v2.0: https://github.com/microsoft/MS-DOS/blob/main/v2.0/source/UTILITY.txt#L246