Introduction
In Linux and MacOS environments, you can terminate standard input by outputting EOF (end of file) using the CTRL-D
keyboard shortcut.
In Windows, the CTRL-D
key combination does not do the same. Lets look at how to accomplish this in Windows Command Prompt or Powershell.
How to send EOF in Windows
In Windows Command Prompt or Powershell, the equivalent of CTRL-D
requires a two-step sequence:
CTRL-Z
followed by <return>
Try it out with a Python script
Example of a Python script that will read standard input until EOF is reached:
# example.py
import sys
print(sys.stdin.read())
Then execute the file with:
python example.py
Type all you want, press <return>
as many times as you want. When you are done, press CTRL-Z
then <return>
and it will
finish readining standard input and perform the print operation.
Conclusion
After following this guide, you should be able to emulate the CTRL-D
behavior to generate an EOF signal in Windows using CTRL-Z
followed by <return>
.