最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

javascript node.js读取命令行流

IT培训 admin 3浏览 0评论

javascript node.js读取命令行流

我有一个node.js脚本,该脚本使用npm命令程序读取args。

例如node a.js -a "hello" -b "100"

但是在将html数据发送给这样的时候,我有一个问题

node a.js -a "some Html content with double quotes and single quotes" -b "100"

我认为可以发送EOL之类的选项

node a.js -b "100" << EOL
some Html content with double quotes and single quotes
EOL

我如何在node.js中阅读此信息(使用命令程序:)

回答如下:您可以通过这种方式使用readline内置的node.js模块:

readline

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
});

let html = ''

rl.on('line', (input) => {
    if (input === 'EOL')
        console.log('received html: ' + html)
    else
        html+= ' ' + input
});
调用,然后输入HTML,并使用所需的任意行。当输入EOL(在一行中)时,程序将认为HTML输入已完全提供。

javascript node.js读取命令行流

我有一个node.js脚本,该脚本使用npm命令程序读取args。

例如node a.js -a "hello" -b "100"

但是在将html数据发送给这样的时候,我有一个问题

node a.js -a "some Html content with double quotes and single quotes" -b "100"

我认为可以发送EOL之类的选项

node a.js -b "100" << EOL
some Html content with double quotes and single quotes
EOL

我如何在node.js中阅读此信息(使用命令程序:)

回答如下:您可以通过这种方式使用readline内置的node.js模块:

readline

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
});

let html = ''

rl.on('line', (input) => {
    if (input === 'EOL')
        console.log('received html: ' + html)
    else
        html+= ' ' + input
});
调用,然后输入HTML,并使用所需的任意行。当输入EOL(在一行中)时,程序将认为HTML输入已完全提供。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论