user13232362
user13232362

Reputation: 13

Manually reading multiple lines of input in terminal

I am writing a python code for a class which needs multiple lines of inputs.

For example I need the input to be in the format:

3 14
12 10
12 5
10 5

When entering this manually on the terminal, I do not know how to signal an end of input.

I have been working around it by entering the inputs in txt files and reading these.

Upvotes: 0

Views: 110

Answers (3)

Diego Torres Milano
Diego Torres Milano

Reputation: 69368

On linux and unix you can find what the EOF char is using

stty -a

it will show something like

...
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <under>;
...

indicating the eof is ^D, which you can also change using stty.

Then, you can type ^D to signal EOF to a process that's reading its input from the terminal.

Upvotes: 0

Ljm Dullaart
Ljm Dullaart

Reputation: 4989

Besides the control-d, in bash, you can also:

pythonscript <<EOF
3 14
12 10
12 5
10 5
EOF

Upvotes: 0

Tim Roberts
Tim Roberts

Reputation: 54743

On Linux, use Ctrl+D to type "end of file". On Windows, use Ctrl+Z.

Upvotes: 2

Related Questions