RKCROCKS144's blog

By RKCROCKS144, history, 7 weeks ago, In English

I recently started using Node JS for programming, and I had written code that take input from stdin (command prompt) in windows. The difficulty arises here is that I go on inputting values and it didn't stopped (i.e. didn't reached the end). I searched over internet and found some saying that use CTRL-D or CTRL-V, but both is not working for me. Is there anything missed up or any other method to resolve it.

Any help would be appreciated. Thanks to community.

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Here is the code I had written.


process.stdin.resume(); let inputstring = ''; let currentLine = 0; process.stdin.on('data', (inputStdin) => { inputstring += inputStdin; process.stdout.write("input Called\n"); }); process.stdin.on('end', () => { inputstring = inputstring.split('\n'); let t = Number(inputstring[0]); let i = 1; process.stdout.write("End Called\n"); while (t--) { let x = Number(inputstring[i++]); solve(x); } }); function solve(n) { for (let i = n; i > 0; --i) { console.log(i); } }
  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Why did you write the code in the comments? Why not in the blog itself?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

replace "process.stdin.on('end',function)" to "process.on("SIGINT", the function)" and then use ctrl+C to end