Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Node.js中的shell命令获取数据/输出_Javascript_Node.js - Fatal编程技术网

Javascript 从Node.js中的shell命令获取数据/输出

Javascript 从Node.js中的shell命令获取数据/输出,javascript,node.js,Javascript,Node.js,我正在尝试将shell命令的输出输入到我的node cli应用程序中。我已经尝试了很多东西,但似乎没有任何东西能让我得到输出 我运行的命令包含以下步骤: $ particle token list Checking with the cloud... ? Using account ****@****.com Please enter your password: [hidden] ? Please enter a login code [optional] __PASSWORD_ONLY_

我正在尝试将shell命令的输出输入到我的node cli应用程序中。我已经尝试了很多东西,但似乎没有任何东西能让我得到输出

我运行的命令包含以下步骤:

$ particle token list
Checking with the cloud...
? Using account ****@****.com
Please enter your password: [hidden]
? Please enter a login code [optional] 

__PASSWORD_ONLY__ (active)
token: sometoken here //this is what I and trying to get mainly
我正在从我的应用程序运行它,就像

const execute = require('child_process').spawnSync;


    const child = execute('particle', ["token", "list"], {encoding: 'utf-8'});
    
    if(child.error) {
        console.log("ERROR: ",child.error);
    }
    console.log("stdout: ",child.stdout);
    console.log("stderr: ",child.stderr);
    console.log("exist code: ",child.status);
当我运行它时,我得到

$ node test.js       
stdout:  ? Using account ****@****.com
Please enter your password: [input is hidden] 
stderr:  Checking with the cloud...

exist code:  255
我尝试了一些通过搜索找到的其他方法,但没有多大帮助。我可以尝试什么,以便命令在输入后完成并返回所有输出?非常感谢您的帮助


PS:它不必是
spawnSync
或任何同步方法,仅用于测试目的。

为什么不使用?我可以,但实际上我正在尝试自学node.js:中的一些角点和内容。)