# Checking if stdin is readable on Windows

**URL:** <https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790>\
**Category:** Python Help\
**Created:** [November 1, 2026, 4:24am UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790 "2026-11-01T04:24:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianofdoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/adrianofdoom/32/22114_2.png) [@adrianofdoom](https://discuss.python.org/u/adrianofdoom)\
**Post date:** [November 1, 2026, 4:24am UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/1 "2026-11-01T04:24:35Z")

</div>

In one of my packages, I have a cli tool and I use a function to see if there is anything to read on stdin for piping video in to my cli tool.

```python
def stdin_is_readable():
    """
    stdin_is readable, detect data on stdin.
    """
    readable, _, _ = select.select([sys.stdin], [], [], 0)
    return sys.stdin in readable

```

**This works great on Unix and Linux, but apparently fails on Windows.**

```python
 File "...\threefive\cli.py", line 468, in threefivecli
    chk_funk_map()
File "...\threefive\cli.py", line 419, in chk_funk_map
    args = chk_stdin(args)
File "...\threefive\cli.py", line 170, in chk_stdin
    if stdin_is_readable():
File "...\threefive\cli.py", line 150, in stdin_is_readable
    readable, _, _ = select.select([sys.stdin], [], [], 0)
OSError: [WinError 10093] Either the application has not called WSAStartup, or WSAStartup failed

```

**I was raised in a UNIX household, I know nothing about Windows.** I am very hesitant to add Windows specific code to my work.

The fix that was suggested looks like this

```python
import os, stat, sys

def stdin_is_readable():
    if sys.platform != "win32":
        readable, _, _ = select.select([sys.stdin], [], [], 0)
        return sys.stdin in readable
    try:
        fd = sys.stdin.fileno()
    except (AttributeError, OSError, ValueError):
        return False
    if os.isatty(fd):
        return False
    st = os.fstat(fd)
    if stat.S_ISREG(st.st_mode):
        return st.st_size > 0
    import ctypes, msvcrt
    from ctypes import wintypes
    avail = wintypes.DWORD(0)
    ok = ctypes.windll.kernel32.PeekNamedPipe(
        wintypes.HANDLE(msvcrt.get_osfhandle(fd)), None, 0, None, ctypes.byref(avail), None)
    return bool(ok) and avail.value > 0

```

I’m just look for some feedback on the solution.  
**Is the solution feasible and reasonable?**

---

<div class="post-metadata">

**Author:** ![adrianofdoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/adrianofdoom/32/22114_2.png) [@adrianofdoom](https://discuss.python.org/u/adrianofdoom)\
**Post date:** [November 1, 2026, 6:16am UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/2 "2026-11-01T06:16:49Z")

</div>

How about:

```python
import sys

def stdin_is_readable():
    return not sys.stdin.isatty()

```

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 1, 2026, 10:23am UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/3 "2026-11-01T10:23:02Z")

</div>

Select on Windows only works with BSD Network Sockets as far as I recall.  
You would need to the WIN32 API to figure what is stdin is readable I think.

> [@adrianofdoom](#):
>
> ```python
> def stdin_is_readable():
> return not sys.stdin.isatty()
> 
> ```

If you pipe into your command the stdin is not a tty.

Maybe it’s good enough to assume that if stdin is not a tty then you can read video data from stdin?

---

<div class="post-metadata">

**Author:** ![adrianofdoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/adrianofdoom/32/22114_2.png) [@adrianofdoom](https://discuss.python.org/u/adrianofdoom)\
**Post date:** [November 6, 2026, 8:22pm UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/4 "2026-11-06T20:22:50Z")

</div>

That’s all I need to determine in that function is if it’s readable. My thinking is if it’s not a tty, then it has to readable like a file, what else could it be…maybe I better look that up.

```python
not sys.stdin.isatty()

```

Works on Linux and OpenBSD, I need to find a Windows machine and try it.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 6, 2026, 8:36pm UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/5 "2026-11-06T20:36:03Z")

</div>

> [@adrianofdoom](#):
>
> what else could it be

Well since you ask. It could be that stdin is not a file handle at all.

---

<div class="post-metadata">

**Author:** ![adrianofdoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/adrianofdoom/32/22114_2.png) [@adrianofdoom](https://discuss.python.org/u/adrianofdoom)\
**Post date:** [November 19, 2026, 1:10am UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/6 "2026-11-19T01:10:36Z")

</div>

What I meant was what else could stdin be besides a tty or file handle.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [November 19, 2026, 7:36am UTC](https://discuss.python.org/t/checking-if-stdin-is-readable-on-windows/109790/7 "2026-11-19T07:36:51Z")

</div>

It could be a pipe.
