Giter Club home page Giter Club logo

Comments (15)

anseki avatar anseki commented on May 18, 2024

Hi, Gomez
Does "keeps reading" mean that a method doesn't return? It's not that receiving a empty text from a method?
That is, The "NEXT LINE" isn't shown by this code?:

var rl = require('readline-sync');
input = rl.prompt();
console.log('NEXT LINE');

from readline-sync.

anseki avatar anseki commented on May 18, 2024

And, the prompt text (default: >) is shown?

from readline-sync.

xerz-one avatar xerz-one commented on May 18, 2024

It stops executing at that point, trying to read input and keeping stuck. And the prompt is displayed correctly, so I am a 99'9% sure it has a problem with receiving input.

from readline-sync.

anseki avatar anseki commented on May 18, 2024

Ummm... readlineSync works completely on my machine, there seems to be no problem.
(lubuntu-14.04.1, nodejs-v0.10.35, readline-sync-0.4.10)

The setup nodejs was no problem?
Because, I think that it's unusual that the ^C doesn't work.

Try this:

  1. Input below, and push enter key.
/bin/sh `node -e "console.log(require('path').dirname(require.resolve('readline-sync')))"`/read.sh
  1. Type abc, and push enter key.
  2. The abc is shown, and code is finished.

from readline-sync.

xerz-one avatar xerz-one commented on May 18, 2024

That worked! Forgot to mention before - I had the problem while using the Node interpreter. So guess that's what happened. I was executing my code by invoking require() manually, and when I tried to debug, I never ran directly a script (take a look, there was no var when defining a variable)

Now - could this bug be fixed? It seems that the problem is that node.js may be trying to read the input twice, in two different ways simultaneously. Or something like that.

from readline-sync.

anseki avatar anseki commented on May 18, 2024

Ah, you tried in REPL. I understood.
The any codes that handles stdin don't work in REPL because REPL handles stdin (TTY). That is, it's like emulating the shell.
This is not bug. This is design of nodejs. And, nobody want input on REPL.

Try this code in REPL:

process.stdin.pause()

from readline-sync.

xerz-one avatar xerz-one commented on May 18, 2024

Ugh, I apologize. How simple. Guess I'll have to study better the APIs!

(and yup, here's someone who wants to read input from REPL. Working on what I consider a cool project. Hi!)

from readline-sync.

xerz-one avatar xerz-one commented on May 18, 2024

Actually -- not working. It still keeps stuck. Here's the source code of the "real" thing:

var os = require('os');
var rl = require('readline-sync');
var child_process = require('child_process');
var sh = require('execSync');

var username = sh.exec("id -un").stdout.replace(os.EOL, '');
var hostname = os.hostname();

module.exports = {
    shell: function (){
        console.log( 'Kuen Shell v0.0.1' );
        console.log( '2015 Francisco Gómez <[email protected]>' + os.EOL );

        process.stdin.pause();
        var loop = true;

        while(loop) {
            rl.setPrompt(username + '@' + hostname + ': ');
            input = rl.prompt();
            try {
                var shExec = sh.exec(input);
                console.log(shExec.stdout);
            } catch(e) {};
        };
    }
}

from readline-sync.

anseki avatar anseki commented on May 18, 2024

If you want to read a line from another stream that is not REPL, I think that you must assign another channel (e.g. remote connection).
But, that idea is not good... Because the REPL is used for debug, that is a easy interactive environment. That will spoil REPL's good interactivity.
If you want to make the code run step by step for debug, the node debug might help you. Or, other debug tools like node-inspector.

So, your code seems to run with no problem in my machine. (some syntax errors are shown. but it's running.)
I tried input shell command (e.g. ls), then the response was shown at screen.
Doesn't sh.exec() method fail? because that depends on system environment.

Try this:

var os = require('os');
var rl = require('readline-sync');
var child_process = require('child_process');
//var sh = require('execSync');
// Dummy Object
var sh = {exec: function(cmd) {
    return {stdout: 'Res of: ' + cmd};
}};

var username = sh.exec("id -un").stdout.replace(os.EOL, '');
var hostname = os.hostname();

module.exports = {
    shell: function (){
        console.log( 'Kuen Shell v0.0.1' );
        console.log( '2015 Francisco Gómez <[email protected]>' + os.EOL );

        process.stdin.pause();
        var loop = true;

        while(loop) {
            rl.setPrompt(username + '@' + hostname + ': ');
            input = rl.prompt();
            try {
                var shExec = sh.exec(input);
                console.log(shExec.stdout);
            } catch(e) {};
        };
    }
}

from readline-sync.

anseki avatar anseki commented on May 18, 2024

I didn't try running readlineSync on node debug. That result might be same as REPL.

from readline-sync.

anseki avatar anseki commented on May 18, 2024

10 days have passed. I think that that problem was already solved, and I close the issue.
If not solved, please reopen it.

from readline-sync.

xerz-one avatar xerz-one commented on May 18, 2024

The bug itself still happens. However, I'm going to try out a different workaround for my idea. Thanks!

from readline-sync.

anseki avatar anseki commented on May 18, 2024

Ok. 😊
If that bug you said is the bug of readlineSync, tell me please.

from readline-sync.

CreeperDrop avatar CreeperDrop commented on May 18, 2024

I don't think that's a bug in readline-sync because it happens also if you try a different loop such as a for loop.

from readline-sync.

anseki avatar anseki commented on May 18, 2024

Hi @CreeperDrop, thank you for the comment.

Yes, that is not a bug. It was clearly indicated that there was the problem in @espectalll's environment. (e.g. REPL)

from readline-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.