Tag: stdin

无法在nodejs脚本中设置RawMode

最初我试图设置原始模式使用tty.setRawMode(true)日志告诉我,这已被弃用,我应该使用process.stdin.setRawMode(true)但该命令给我TypeError: Object #<Socket> has no method 'setRawMode'我似乎无法find其他任何原始模式的文档,build议任何其他apporoaches任何人都知道如何得到这个工作? 我正在使用版本0.10.25

ChildProcess:stdin没有被Python readline读取

我正在试图通过使用child_process stdin / out从Node的Python脚本进行交互,如下所示: var p = require('child_process').spawn('python', ['test_io.py']); p.stdout.on('data', function(data) { console.log(data.toString()); }); p.stdin.write('thing'); 这是相关的Python部分: import io import sys _input = io.open(sys.stdin.fileno()) _output = io.open(sys.stdout.fileno(), 'w') while True: _output.write(_input.readline()) 但是,现在看来,Python脚本并不是通过stdin.write读取“东西”。 这些写不应该缓冲? 我在这里做错了什么。 提前致谢。

将条件语句插入到process.stdin的可读stream中

那么,我试图将一个简单的if语句传递给NodeJS中的一个process.stdin可读stream。 但它似乎不工作。 代码如下: process.stdin.on('readable', function() { var chunk = process.stdin.read(); if (chunk !== null && chunk == 'foo') { process.stdout.write('true\n'); } else if (chunk !== null) { process.stdout.write('false\n'); } 有谁知道,我在这里做错了什么? 我也试过chunk == 'foo\n'但是,没有运气。 它唯一的工作是当我设置块值为一个数字,如chunk == 10 。

从标准input读取大节点的input

我必须能够读取标准input(10 ^ 5空格分隔的数字)的大input。 任何超过10 ^ 3和readline的input只需要200秒就可以读取,我需要在不到5秒的时间内完成。 我应该使用除readline以外的东西,还是有一种方法来增加readline的缓冲区或什么?

STDOUT在STDIN前面提示?

我有一个setInterval每秒logging时间。 我想用STDIN来执行脚本中的命令,但是STDOUT在我input的时候正在移动光标,并把它自己放到提示符中。 我没有太多的提示经验,刚开始潜水。 脚本: setInterval(function(){ console.log(new Date().toUTCString()); },1000) var readline = require('readline'); var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question("Hi there, how are you?", function(answer) { }); 输出: Hi there, how are you?Mon, 17 Dec 2012 16:20:34 GMT fine Mon, 17 Dec 2012 16:20:35 GMT Mon, 17 Dec 2012 16:20:36 GMT Mon, 17 […]

nodejs – 类似于标准input的标准input

我想模拟bashinput行为(例如按向上箭头访问input历史logging,按Ctrl + C取消input,按Ctrl + D退出)。 但是,如果我想转义箭头键例如(默认情况下被^ [[A,^ [[B,^ [[C和^ [[D]replace,我需要设置原始模式 ,然后,每次按下按键时都会触发input事件。 这是有用的,但后来我需要硬编码的基本input行为,如返回键或删除键… 那么,有没有办法,也许通过pipe道inputstdin,访问input在原始模式和非原始模式?

“process.stdin.on”中的“.on”在哪里?

我是Node.js的新手 我在他们的网站上,我有一个朋友的示例代码包含“标准input”。 我去寻找什么标准input,我现在知道。 另外,在Node.js的网站上,他们使用“ stdin.on ”。 我找不到任何关于它的事情。 也许有人可以填补我? 🙂 process.stdin.setEncoding('utf8'); process.stdin.on('readable', () => { var chunk = process.stdin.read(); if (chunk !== null) { process.stdout.write(`data: ${chunk}`); } }); process.stdin.on('end', () => { process.stdout.write('end'); }); 我希望有人能够在非专家层面上向我解释这一点。 我知道我可以买一本书,然后开始阅读,但是我在业余时间为了娱乐而做这个。

节点js与shell应用程序交互

网上有很多关于如何产生一个subprocess的节点js例子,然后把结果作为一个string来处理。 但… 我想与孩subprocess“互动”。 例如,我将如何编写节点js应用程序,而不是通过调用“ python ”开始,然后在继续input另一个任意语句“ 4+4 ”之前键入语句“ 1+1 ”,让我捕获结果“ 2 ” ? (通过“types”我假设它将需要stream数据到该进程使用的标准input)。

强制Node.js刷新写入subprocess

我产生了一个像这样的subprocess: var child = require('child_process'); var proc = child.spawn('python', ['my_script.py', '-p', 'example']); 我还设置了一些数据处理: proc.stdin.setEncoding('utf8'); proc.stdout.setEncoding('utf8'); proc.stderr.setEncoding('utf8'); proc.stdout.on('data', function (data) { console.log('out: ' + data); }); proc.stderr.on('data', function (data) { console.log('err: ' + data); }); proc.on('close', function (code) { console.log('subprocess exited with status ' + code); proc.stdin.end(); }); 我的Python脚本从stdin读取行,并为每行执行一些操作,并打印到stdout 。 它在shell中工作正常(我写一行,我立即得到输出),但是当我在Node中这样做: for (var i = 0; […]

如何在debugging器界面中将东西馈送到脚本的stdin中?

我跑了: node debug f.js 现在我有一个: debug> 提示。 我怎么能切换我input到terminal的东西之间被解释为debugging命令,它被馈送到脚本的stdin?