简体   繁体   English

奇怪的输出“

[英]Weird output "<Buffer" in child_process.spawn

Trying to write a script to dump my MongoDB to afterwards restore it in a Test database again.试图编写一个脚本来转储我的 MongoDB,然后再次将其恢复到测试数据库中。

const {spawn} = require('child_process');

const backupDB = spawn('C:\\_Apps\\mongo\\bin\\mongodump.exe', [
    '--host', 'localhost',
    '--port', '27019',
    '--collection', 'ops',
    '--db', 'prod',
    '--out', "C:\\_Apps"],
    {shell: true}
);

backupDB.stdout.on('data', (data) => {
    console.log(data.toString());
});

backupDB.stderr.on('data', (data) => {
    console.log('Error: ', data);
});

backupDB.stderr.on('close', (code) => {
    console.log('Exit Code: ', code);

Weirdly the script does what it is supposed to (I can find the output BSON under the specified location), but the output is cryptic:奇怪的是,脚本做了它应该做的事情(我可以​​在指定的位置找到输出 BSON),但输出是神秘的:

    Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 30 38 2e 37 33 32 2b 30 32 30 30 09 77 72 69 74 69 6e 67 20 73 6d 61 72 74 4f 52 2e 6f 70 73 20 74 ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 31 31 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 31 34 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 31 37 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 32 30 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 32 33 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 32 36 2e 32 36 34 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 32 39 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 33 32 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 33 35 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 33 38 2e 32 36 35 2b 30 32 30 30 09 5b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 34 31 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 34 34 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 34 37 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 35 30 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 35 33 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 35 36 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 36 3a 35 39 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 30 32 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 30 35 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 30 38 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 31 31 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 31 34 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 31 37 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 32 30 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 32 33 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 32 36 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 32 39 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 23 23 2e 2e 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 33 32 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 23 23 23 23 2e 2e 2e 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 33 35 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 2e 2e 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 33 38 2e 32 36 35 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 2e ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 34 31 2e 32 36 36 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 34 33 2e 33 34 32 2b 30 32 30 30 09 5b 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ... >
Error:  <Buffer 32 30 31 39 2d 30 36 2d 32 37 54 31 34 3a 32 37 3a 34 33 2e 33 34 32 2b 30 32 30 30 09 64 6f 6e 65 20 64 75 6d 70 69 6e 67 20 73 6d 61 72 74 4f 52 2e ... >
Exit Code:  false

That output is just encoded text.该输出只是编码文本。

Try this to see the real output:试试这个看看真正的输出:

backupDB.stderr.on('data', (data) => {
    console.log('Error: ', data.toString('ascii'));
});

Note that this output is coming from stderr , not stdout请注意,此输出来自stderr ,而不是stdout

The stuff that you posted translates as:您发布的内容翻译为:

2019-06-27T14:26:08.732+0200    writing smartOR.ops t
2019-06-27T14:26:11.265+0200    [....................
2019-06-27T14:26:14.265+0200    [....................
2019-06-27T14:26:17.265+0200    [....................
2019-06-27T14:26:20.265+0200    [....................
2019-06-27T14:26:23.265+0200    [....................
2019-06-27T14:26:26.264+0200    [....................
2019-06-27T14:26:29.265+0200    [....................
2019-06-27T14:26:32.265+0200    [....................
2019-06-27T14:26:35.265+0200    [....................
2019-06-27T14:26:38.265+0200    [....................
2019-06-27T14:26:41.265+0200    [###.................
2019-06-27T14:26:44.266+0200    [###.................
2019-06-27T14:26:47.265+0200    [###.................
2019-06-27T14:26:50.265+0200    [###.................
2019-06-27T14:26:53.265+0200    [###.................
2019-06-27T14:26:56.265+0200    [###.................
2019-06-27T14:26:59.265+0200    [###.................
2019-06-27T14:27:02.265+0200    [###.................
2019-06-27T14:27:05.266+0200    [###.................
2019-06-27T14:27:08.265+0200    [###.................
2019-06-27T14:27:11.265+0200    [###.................
2019-06-27T14:27:14.266+0200    [#####...............
2019-06-27T14:27:17.266+0200    [#####...............
2019-06-27T14:27:20.266+0200    [#######.............
2019-06-27T14:27:23.266+0200    [########............
2019-06-27T14:27:26.265+0200    [##########..........
2019-06-27T14:27:29.265+0200    [############........
2019-06-27T14:27:32.265+0200    [##############......
2019-06-27T14:27:35.265+0200    [#################...
2019-06-27T14:27:38.265+0200    [###################.
2019-06-27T14:27:41.266+0200    [####################
2019-06-27T14:27:43.342+0200    [####################
2019-06-27T14:27:43.342+0200    done dumping smartOR.

You can decode it like this:你可以这样解码:

backupDB.stdout.on('data', (data) => {
 console.log(Buffer.from(data).toString());
});

Inside toString() you can provide any encoding you wanttoString()中,您可以提供所需的任何编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当将child_process.spawn()方法与{stdio:&#39;inherit&#39;}一起使用时,父级是否有可能从子进程接收输出? - When using the child_process.spawn() method with {stdio: 'inherit'}, is it possible for the parent receive output from the child process? node.js - 如何调整 child_process.spawn() 的标准输出缓冲区大小(又名 highWaterMark)? - node.js - How to adjust the the stdout buffer size (aka highWaterMark) of child_process.spawn()? 从child_process.spawn访问过程对象 - Accessing process object from child_process.spawn 如何使用child_process.spawn的管道选项? - How to use the pipe option of `child_process.spawn`? 如何使用JavaScript杀死Linux child_process.spawn? - How to kill a linux child_process.spawn using javascript? 有没有办法在child_process.spawn和父级之间进行通信? - Is there a way to communicate between child_process.spawn and parent? NodeJs:检测以child_process.spawn启动的程序何时准备就绪? - NodeJs: Detect when program started with child_process.spawn is ready? Node.js:捕获`child_process.spawn`的STDOUT - Node.js: Capture STDOUT of `child_process.spawn` node.js脚本中的child_process.spawn ENOENT问题 - child_process.spawn ENOENT issue in nodejs script node.js child_process.spawn no stdout除非&#39;inherit&#39; - node.js child_process.spawn no stdout unless 'inherit'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM