Skip to content

Accessing stdin with file descriptor 0 on Windows causes exception if there's no input / if stdin is closed #19831

Closed
@mklement0

Description

@mklement0
  • Version: v9.11.1
  • Platform: Windows 10 Pro (64-bit; v10.0.15063)
  • Subsystem: fs module

On Windows, run the following from a cmd.exe console ("Command Prompt"):

:: Echo stdin input

::  OK: Nonempty stdin input.
echo hi | node -pe "require('fs').readFileSync(0).toString()"

:: BREAKS ON WINDOWS: no stdin input, which should *prompt* for it when run in a terminal.
node -pe "require('fs').readFileSync(0).toString()"

:: BREAKS ON WINDOWS: stdin input closed; should return an empty line.
node -pe "require('fs').readFileSync(0).toString()" < NUL

The last 2 commands break as follows:

fs.js:531
    binding.fstat(fd);
            ^

Error: EISDIR: illegal operation on a directory, fstat
    at tryStatSync (fs.js:531:13)
    at Object.fs.readFileSync (fs.js:567:3)
...

Using .readFile() and the readline module is equally affected.

On Unix platforms, the behavior is as expected in all cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.stdioIssues and PRs related to stdio.v18.xIssues that can be reproduced on v18.x or PRs targeting the v18.x-staging branch.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions