Ctrl-Z handling on stdin read

713 views
Skip to first unread message

tech...@gmail.com

unread,
Mar 17, 2015, 12:24:49 PM3/17/15
to golan...@googlegroups.com, matt...@gmail.com
Hi,

it is impossible to end input from stdin in Go programs (like in Python etc).

I wonder what keeps this PR from being reviewed? And how the PR avoids
premature exit when files with Ctrl-Z character are piped into it?

Benjamin Measures

unread,
Mar 17, 2015, 2:44:42 PM3/17/15
to golan...@googlegroups.com, matt...@gmail.com, tech...@gmail.com
On Tuesday, 17 March 2015 16:24:49 UTC, tech...@gmail.com wrote:
I wonder what keeps this PR from being reviewed?

There was a disagreement as to where it should be handled:
afaict both approaches seemed to have issues.

The issue stems from DOS/Windows never producing EOF for console input (it's not a "real" terminal).

anatoly techtonik

unread,
Mar 17, 2015, 5:45:52 PM3/17/15
to Benjamin Measures, golan...@googlegroups.com, matt...@gmail.com
What is the issue exacly? `copy con xxx.txt` works both in DOS and Windows
for creating multiline files in console, and you terminate the output by sending
CTRL-Z from a blank line. I thought it is EOF.

--
anatoly t.

Benjamin Measures

unread,
Mar 19, 2015, 7:14:13 AM3/19/15
to golan...@googlegroups.com, saint....@gmail.com, matt...@gmail.com, tech...@gmail.com
On Tuesday, 17 March 2015 21:45:52 UTC, anatoly techtonik wrote:
On Tue, Mar 17, 2015 at 9:44 PM, Benjamin Measures <saint....@gmail.com> wrote:
> The issue stems from DOS/Windows never producing EOF for console input (it's
> not a "real" terminal).

What is the issue exacly?

In *nix, it is the terminal that signals EOF on ctl-d.

In Windows, there is no console driver. Windows passes the ctl-z to the application, and it is up to the application to interpret however it may. It's an ugly legacy left over from CP/M compat.

anatoly techtonik

unread,
Mar 19, 2015, 10:14:10 AM3/19/15
to Benjamin Measures, golan...@googlegroups.com, Yasuhiro MATSUMOTO
On Thu, Mar 19, 2015 at 2:14 PM, Benjamin Measures
<saint....@gmail.com> wrote:
> On Tuesday, 17 March 2015 21:45:52 UTC, anatoly techtonik wrote:
>>
>> On Tue, Mar 17, 2015 at 9:44 PM, Benjamin Measures <saint....@gmail.com>
>> wrote:
>> > The issue stems from DOS/Windows never producing EOF for console input
>> > (it's
>> > not a "real" terminal).
>>
>> What is the issue exacly?
>
> In *nix, it is the terminal that signals EOF on ctl-d.
>
> In Windows, there is no console driver. Windows passes the ctl-z to the
> application, and it is up to the application to interpret however it may.
> It's an ugly legacy left over from CP/M compat.

Interesting. How does Windows do this? Is there separate event
handling channel that is different from stdin? Can I create a file and
pipe it to stdin that will end prematurely, because there is encoded
ctrl-z sequence inside?
--
anatoly t.

Benjamin Measures

unread,
Mar 19, 2015, 7:43:42 PM3/19/15
to golan...@googlegroups.com, saint....@gmail.com, matt...@gmail.com, tech...@gmail.com
On Thursday, 19 March 2015 14:14:10 UTC, anatoly techtonik wrote:
Can I create a file and pipe it to stdin that will end prematurely, because there is encoded ctrl-z sequence inside?

[...] will create a text file with an embedded Control-Z (ASCII code 26) between the two lines of text. [...] You can now try and read the file using command line facilities. On Windows:
c:\users\neilb\home\temp>type myfile.txt
line
1
Notice only the first line is displayed. On Linux:
[neilb@ophelia temp]$ cat myfile.txt
line
1
?line 2

tech...@gmail.com

unread,
Mar 27, 2015, 9:04:09 AM3/27/15
to golan...@googlegroups.com, saint....@gmail.com, matt...@gmail.com, tech...@gmail.com
I'd like to emulate CTRL-Z and CTRL-D handling, because it is a good feature to have. But I don't want it to stand in a way when somebody pipes an actual file to stdin. Is there a way in Go to distinguish when stdin is getting information from file or from keyboard?
Reply all
Reply to author
Forward
0 new messages