Comments (15)
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.
And, the prompt text (default: >
) is shown?
from readline-sync.
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.
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:
- Input below, and push enter key.
/bin/sh `node -e "console.log(require('path').dirname(require.resolve('readline-sync')))"`/read.sh
- Type
abc
, and push enter key. - The
abc
is shown, and code is finished.
from readline-sync.
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.
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.
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.
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.
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.
I didn't try running readlineSync on node debug
. That result might be same as REPL.
from readline-sync.
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.
The bug itself still happens. However, I'm going to try out a different workaround for my idea. Thanks!
from readline-sync.
Ok. 😊
If that bug you said is the bug of readlineSync, tell me please.
from readline-sync.
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.
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)
- question does not print the expected character HOT 4
- looking for help in building the console application with syntax highlight HOT 9
- Non-ASCII Character Issues HOT 9
- `hideEchoBack: true` disables backspace. HOT 3
- Is there any way to take multi-line input? HOT 6
- Error on Windows when input is redirected HOT 9
- Chinese character problem HOT 12
- Allow movements like in bash terminal (Left, Right) HOT 9
- Readline-sync not working in VSCode HOT 9
- Read a markdown file line by line in sync HOT 23
- Multiple select HOT 5
- Can't distinguish between EOD and a blank input line HOT 9
- a qusetion about encoding HOT 4
- Other code cannot be run HOT 3
- "Assertion `(argc) == (5)' failed." error on calling functions HOT 8
- readline-sync does not print special/unicode chars, bu tusing normal console.log() works fine HOT 2
- node.js may crash on windows 10 when console in/out is redirected HOT 3
- keypress event not firing after keyInSelect HOT 2
- Adding a default answer option to keyInYN* HOT 5
- Cannot redirect standard input HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from readline-sync.