4

I love the pathlib.Path api and use it a lot for quick cli tools. Especially with typer. I have a few tightly related questions:

  • In UNIX cli commands - is the de facto standard for stdin. Is that the same under Windows?
  • Is there a clean, cross-platform way to have a pathlib.Path object (or actually the {POSIX,Windows}Path it automatically becomes) to represent stdin?
  • And what about stdout?
Chris Wesseling
  • 6,226
  • 2
  • 36
  • 72
  • 1
    What would you expect such an object to *do*? It can’t expose directory parts, for instance. Modern Unix systems do have `/dev/stdin`, but that doesn’t sound like what you want. – Davis Herring Oct 28 '21 at 16:41
  • @DavisHerring Have a Path instance p, such that p.open() returns an open file descriptor for stdin, ready for reading. – Chris Wesseling Oct 28 '21 at 21:16
  • This post deals with idea I think you're going after: https://codereview.stackexchange.com/questions/98393/context-managers-that-also-deal-with-sys-stdin-and-sys-stdout I'm sure you were looking for something much simpler though. – Sebastian Sep 09 '22 at 13:55
  • @Sebastian that code predates pathlib and, funny, was the pattern [I was using](https://github.com/python/cpython/issues/89807) when I asked this. I like functions to be simple, so having one accept just a pathlib.Path for all cases, such that it can call .open() on the parameter without inspection, is what I'm after. – Chris Wesseling Sep 12 '22 at 08:39

0 Answers0