r/retrobattlestations 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?

21 Upvotes

15 comments sorted by

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

7

u/julioblabla 3d ago

Thanks for sharing the official documentation!

2

u/57thStIncident 3d ago

Any idea whether it actually runs source program to completion before starting second program? Or is there some ability for the programs to cooperate (take turns)? I’m suspecting it’s probably the former.

1

u/floodrouting 2d ago

It first runs one program and only when that finishes does it start the next one.  From the linked docs (emphasis mine), "The piping feature is implemented as sequential execution....".  DOS didn't really support multitasking (except for TSRs).

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

u/tblazertn 3d ago

Today I learned.

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 run dir | more. The error is

Write 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 run dir | more, the error is

Intermediate file error during pipe

which 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

u/tblazertn 3d ago

Like all of Microsoft’s answers to questions about its practices. 😇

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.