I'm writing a command line tool. One of the things this tool can do (certainly not uniquely) is read it's input from stdin. I was testing this interactively (by typing input, rather than cat'ing a file in) when I noticed that I have no clue how to signal EOF to it.
I have spent an inordinate amount of time tonight Googling this and found nothing helpful. I searched SO, as well. Please feel free to point me to a duplicate question, but I did my due diligence, I promise.
EDIT: It might be helpful (?) to mention that I'm doing this on Windows. So I believe the terminal is more or less a branded MinGW?
the “end-of-file” (EOF) key combination can be used to quickly log out of any terminal. CTRL-D is also used in programs such as “at” to signal that you have finished typing your commands (the EOF command). key combination is used to stop a process. It can be used to put something in the background temporarily.
Put a Multi-line String to a File in BashThe EOF is known as the Here Tag . The Here Tag tells the shell that you will input a multi-line string until the Here Tag . The << is used to set the Here Tag . The > is used to redirect the input content to a specified file, multiline.
This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended. Similarly, in bash, the EOF operator is used to specify the end of the file.
It should be sent by the user. So is it that only the user can invoke EOF in stdin by pressing Ctrl + Z ? Yes, you can set the EOF indicator for stdin with a special key combination you can input in the console, for linux console that is Ctrl + D and for windows it's Ctrl + Z .
A simple work-around that I'm using in Git Bash on Windows is to cat the input to the program.
E.g., instead of running
java my_package.Main
You can run
cat | java my_package.Main
This works because the cat program is a linuxy-program that can accept the end of message from the terminal, and java can receive the end of message command properly through the pipe.
So when using this command, you can type Ctl-D after typing the message and the java program will see the end of message correctly.
If you're trying to send EOF to a program's input under Windows, Ctrl-Z
is what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With