什么是EOF在cygwin在windows 10 [英] what is EOF in cygwin in windows 10

查看:379
本文介绍了什么是EOF在cygwin在windows 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在win8.1上运行cygwin,同时给一个程序输入CTRL-Z来表示EOF。今天我在win10上安装了cygwin,并运行a.out。输入输入数据后,当我按CTRL-Z时,我得到消息暂停,我回到shell提示符。我试过这个用bash和csh,结果相同。 CTRL-D也不工作,它正在杀死shell。

I used to run cygwin on win8.1, and while giving inputs to a program CTRL-Z used to denote EOF. Today I installed cygwin on win10, and ran "a.out". After typing in the input data, when I press CTRL-Z I get the message "Suspended" and I get back the shell prompt. I tried this with bash and csh, same result. CTRL-D also does not work, it is killing the shell.

只是为了确认这只是这个问题,没有别的,我创建了一个新的input.txt文件,并在其中输入相关的输入数据,并运行a.out

Just to confirm that it is only this problem and nothing else, I created a new input.txt file, and entered the relevant input data in it, and ran "a.out < input.txt", and it worked fine. So the problem is only in defining EOF for STDIN.

如何解决这个问题?

注意:我要关闭此问题,并在一个新问题中提供更多详细信息在Windows上的cygwin上的java中读取EOF

Note: I am closing this question, and put in more details in a new question reading till EOF in java on cygwin on windows-10

推荐答案

在类似Unix的系统上,包括Cygwin,Ctrl- D默认配置为触发从tty(终端/键盘)读取时,文件结束条件。可以使用 stty 命令改变这一点,但看起来你还没有这样做(你几乎肯定不应该这样做)。

On Unix-like systems, including Cygwin, Ctrl-D is (by default) configured to trigger an end-of-file condition when reading from a tty (terminal/keyboard). It's possible to change this using the stty command, but it looks like you haven't done that (and you almost certainly shouldn't).

如果在运行从标准输入读取的程序时输入Ctrl-D,那么根据其到达输入结束的响应方式,它可能会终止您的程序。

If you enter Ctrl-D while running your program that reads from standard input, that will likely terminate your program, depending on how it responds to reaching the end of its input.

Ctrl-Z发送暂停当前程序的信号(某些程序,如交互式shell,能够处理或忽略该信号)。 (Windows使用Ctrl-Z来触发文件结束。)

Ctrl-Z sends a signal that suspends your current program (some programs, such as interactive shells, are able to handle or ignore that signal). (Windows uses Ctrl-Z to trigger end-of-file.)

您描述的行为表示您正在shell提示符下键入Ctrl-D。这给出了shell,而不是您的程序和文件结束条件。 shell通过终止(默认情况下可以使用 set -o ignoreeof 告诉shell忽略它)来做出响应。

The behavior you describe indicates that you're typing Ctrl-D at a shell prompt. This gives the shell, not your program, and end-of-file condition. The shell response to this by terminating (by default; you can use set -o ignoreeof to tell the shell to ignore it).

如果在运行程序时键入Ctrl-D ,它应该正确触发和文件结束条件,并导致程序终止。

If you type Ctrl-D while running your program, it should correctly trigger and end-of-file condition and cause your program to terminate.

更新:通常你应该在任何其他输入之前键入Ctrl-D(导致程序不接收任何输入),或在键入Return之后立即键入。要在行中间触发文件结束,您必须键入Ctrl-D两次 。 (这通常不是一个好主意,因为它导致程序看到一个没有终止换行符的部分行。)

UPDATE: Normally you should type Ctrl-D either before any other input (resulting in the program receiving no input at all), or immediately after typing Return. To trigger end-of-file in the middle of a line, you'd have to type Ctrl-D twice. (This is usually not a great idea, since it results in the program seeing a partial line with no terminating newline character.)

这篇关于什么是EOF在cygwin在windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆