Cannot trigger 'end' event using CTRL D when reading from stdin
In the following code
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
process.stdout.write('data: ' + chunk);
});
process.stdin.on('end', function() {
process.stdout.write('end');
});
i can't trigger the 'end' event using ctrl+D, and ctrl+C just exit without triggering it.
hello
data: hello
data
data: data
foo
data: foo
^F
data: ♠
^N
data: ♫
^D
data: ♦
^D^D
data: ♦♦
node.js events stdin
add a comment |
In the following code
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
process.stdout.write('data: ' + chunk);
});
process.stdin.on('end', function() {
process.stdout.write('end');
});
i can't trigger the 'end' event using ctrl+D, and ctrl+C just exit without triggering it.
hello
data: hello
data
data: data
foo
data: foo
^F
data: ♠
^N
data: ♫
^D
data: ♦
^D^D
data: ♦♦
node.js events stdin
add a comment |
In the following code
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
process.stdout.write('data: ' + chunk);
});
process.stdin.on('end', function() {
process.stdout.write('end');
});
i can't trigger the 'end' event using ctrl+D, and ctrl+C just exit without triggering it.
hello
data: hello
data
data: data
foo
data: foo
^F
data: ♠
^N
data: ♫
^D
data: ♦
^D^D
data: ♦♦
node.js events stdin
In the following code
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
process.stdout.write('data: ' + chunk);
});
process.stdin.on('end', function() {
process.stdout.write('end');
});
i can't trigger the 'end' event using ctrl+D, and ctrl+C just exit without triggering it.
hello
data: hello
data
data: data
foo
data: foo
^F
data: ♠
^N
data: ♫
^D
data: ♦
^D^D
data: ♦♦
node.js events stdin
node.js events stdin
asked May 6 '13 at 15:14


MisakiMisaki
59711128
59711128
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I'd change this:
process.stdin.on('end', function() {
process.stdout.write('end');
});
To this:
process.on('SIGINT', function(){
process.stdout.write('n end n');
process.exit();
});
Further resources: process docs
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
add a comment |
I too came upon this problem and found the answer here: Github issue
The readline interface that is provided by windows itself (e.g. the one that you are using now) does not support ^D. If you want more unix-y behaviour, use the readline built-in module and set stdin to raw mode. This will make node interpret raw keypresses and ^D will work. See http://nodejs.org/api/readline.html.
If you are on Windows, the readline interface does not support ^D by default. You will need to change that per the linked instructions.
add a comment |
If you are doing it in context to Hackerrank codepair tool then this is for you.
The way tool works is that you have to enter some input in the Stdin section and then click on Run which will take you to stdout.
All the lines of input entered in the stdin will be processed by the process.stdin.on("data",function(){}) part of the code and as soon as the input "ends" it will go straight to the process.stdin.on("end", function(){}) part where we can do the processing and use process.stdout.write("") to output the result on the Stdout.
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
// This is where we should take the inputs and make them ready.
input += (chunk+"n");
// This function will stop running as soon as we are done with the input in the Stdin
});
process.stdin.on("end", function () {
// When we reach here, we are done with inputting things according to our wish.
// Now, we can do the processing on the input and create a result.
process.stdout.write(input);
});
You can check the flow by pasting he above code on the code window.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16401778%2fcannot-trigger-end-event-using-ctrl-d-when-reading-from-stdin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'd change this:
process.stdin.on('end', function() {
process.stdout.write('end');
});
To this:
process.on('SIGINT', function(){
process.stdout.write('n end n');
process.exit();
});
Further resources: process docs
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
add a comment |
I'd change this:
process.stdin.on('end', function() {
process.stdout.write('end');
});
To this:
process.on('SIGINT', function(){
process.stdout.write('n end n');
process.exit();
});
Further resources: process docs
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
add a comment |
I'd change this:
process.stdin.on('end', function() {
process.stdout.write('end');
});
To this:
process.on('SIGINT', function(){
process.stdout.write('n end n');
process.exit();
});
Further resources: process docs
I'd change this:
process.stdin.on('end', function() {
process.stdout.write('end');
});
To this:
process.on('SIGINT', function(){
process.stdout.write('n end n');
process.exit();
});
Further resources: process docs
answered May 6 '13 at 17:29


thtsigmathtsigma
3,04412028
3,04412028
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
add a comment |
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
but why?....i get this code from the node.js site. Is it incorrect?
– Misaki
May 6 '13 at 17:45
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
What version of Node.js are you using?
– thtsigma
May 6 '13 at 17:50
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
i'm using 0.10.4
– Misaki
May 6 '13 at 17:57
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
I'm not sure on the Why part. I looked around a bit and didn't see any obvious suggestions. My guess is that stdin.on is not receiving an end event, thus it never calls that. But again, its just a guess.
– thtsigma
May 6 '13 at 18:32
add a comment |
I too came upon this problem and found the answer here: Github issue
The readline interface that is provided by windows itself (e.g. the one that you are using now) does not support ^D. If you want more unix-y behaviour, use the readline built-in module and set stdin to raw mode. This will make node interpret raw keypresses and ^D will work. See http://nodejs.org/api/readline.html.
If you are on Windows, the readline interface does not support ^D by default. You will need to change that per the linked instructions.
add a comment |
I too came upon this problem and found the answer here: Github issue
The readline interface that is provided by windows itself (e.g. the one that you are using now) does not support ^D. If you want more unix-y behaviour, use the readline built-in module and set stdin to raw mode. This will make node interpret raw keypresses and ^D will work. See http://nodejs.org/api/readline.html.
If you are on Windows, the readline interface does not support ^D by default. You will need to change that per the linked instructions.
add a comment |
I too came upon this problem and found the answer here: Github issue
The readline interface that is provided by windows itself (e.g. the one that you are using now) does not support ^D. If you want more unix-y behaviour, use the readline built-in module and set stdin to raw mode. This will make node interpret raw keypresses and ^D will work. See http://nodejs.org/api/readline.html.
If you are on Windows, the readline interface does not support ^D by default. You will need to change that per the linked instructions.
I too came upon this problem and found the answer here: Github issue
The readline interface that is provided by windows itself (e.g. the one that you are using now) does not support ^D. If you want more unix-y behaviour, use the readline built-in module and set stdin to raw mode. This will make node interpret raw keypresses and ^D will work. See http://nodejs.org/api/readline.html.
If you are on Windows, the readline interface does not support ^D by default. You will need to change that per the linked instructions.
answered Sep 10 '15 at 6:21


MarkMark
7516
7516
add a comment |
add a comment |
If you are doing it in context to Hackerrank codepair tool then this is for you.
The way tool works is that you have to enter some input in the Stdin section and then click on Run which will take you to stdout.
All the lines of input entered in the stdin will be processed by the process.stdin.on("data",function(){}) part of the code and as soon as the input "ends" it will go straight to the process.stdin.on("end", function(){}) part where we can do the processing and use process.stdout.write("") to output the result on the Stdout.
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
// This is where we should take the inputs and make them ready.
input += (chunk+"n");
// This function will stop running as soon as we are done with the input in the Stdin
});
process.stdin.on("end", function () {
// When we reach here, we are done with inputting things according to our wish.
// Now, we can do the processing on the input and create a result.
process.stdout.write(input);
});
You can check the flow by pasting he above code on the code window.
add a comment |
If you are doing it in context to Hackerrank codepair tool then this is for you.
The way tool works is that you have to enter some input in the Stdin section and then click on Run which will take you to stdout.
All the lines of input entered in the stdin will be processed by the process.stdin.on("data",function(){}) part of the code and as soon as the input "ends" it will go straight to the process.stdin.on("end", function(){}) part where we can do the processing and use process.stdout.write("") to output the result on the Stdout.
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
// This is where we should take the inputs and make them ready.
input += (chunk+"n");
// This function will stop running as soon as we are done with the input in the Stdin
});
process.stdin.on("end", function () {
// When we reach here, we are done with inputting things according to our wish.
// Now, we can do the processing on the input and create a result.
process.stdout.write(input);
});
You can check the flow by pasting he above code on the code window.
add a comment |
If you are doing it in context to Hackerrank codepair tool then this is for you.
The way tool works is that you have to enter some input in the Stdin section and then click on Run which will take you to stdout.
All the lines of input entered in the stdin will be processed by the process.stdin.on("data",function(){}) part of the code and as soon as the input "ends" it will go straight to the process.stdin.on("end", function(){}) part where we can do the processing and use process.stdout.write("") to output the result on the Stdout.
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
// This is where we should take the inputs and make them ready.
input += (chunk+"n");
// This function will stop running as soon as we are done with the input in the Stdin
});
process.stdin.on("end", function () {
// When we reach here, we are done with inputting things according to our wish.
// Now, we can do the processing on the input and create a result.
process.stdout.write(input);
});
You can check the flow by pasting he above code on the code window.
If you are doing it in context to Hackerrank codepair tool then this is for you.
The way tool works is that you have to enter some input in the Stdin section and then click on Run which will take you to stdout.
All the lines of input entered in the stdin will be processed by the process.stdin.on("data",function(){}) part of the code and as soon as the input "ends" it will go straight to the process.stdin.on("end", function(){}) part where we can do the processing and use process.stdout.write("") to output the result on the Stdout.
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
// This is where we should take the inputs and make them ready.
input += (chunk+"n");
// This function will stop running as soon as we are done with the input in the Stdin
});
process.stdin.on("end", function () {
// When we reach here, we are done with inputting things according to our wish.
// Now, we can do the processing on the input and create a result.
process.stdout.write(input);
});
You can check the flow by pasting he above code on the code window.
answered Nov 21 '18 at 7:29


Aavgeen singhAavgeen singh
111110
111110
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16401778%2fcannot-trigger-end-event-using-ctrl-d-when-reading-from-stdin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown