Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I signal EOF to the Git Bash terminal?

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?

like image 503
burfl Avatar asked Mar 28 '13 02:03

burfl


People also ask

How do you signal EOF in terminal?

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.

How do you enter EOF in bash?

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.

What is << EOF in bash?

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.

How do you signal EOF in stdin?

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 .


2 Answers

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.

like image 58
Josiah Yoder Avatar answered Oct 27 '22 00:10

Josiah Yoder


If you're trying to send EOF to a program's input under Windows, Ctrl-Z is what you're looking for.

like image 43
Brendan Dolan-Gavitt Avatar answered Oct 27 '22 01:10

Brendan Dolan-Gavitt