Answer the question
In order to leave comments, you need to log in
Why does Child process(NodeJS) output a buffer instead of a readable string?
Good afternoon. I'm trying to run a Linux command on Nodejs. I do everything through the child process. Here is the code
const spawn = require("child_process").spawn;
const ls = spawn("cbm");
ls.stdout.on("data", (data) => {
console.log(data);
});
ls.stderr.on("data", (data) => {
console.log(`stderr: ${data}`);
});
ls.on("close", (code) => {
console.log(`child process exited with code ${code}`);
});
<Buffer 1b 2c .... >
console.log(data.toString()
'\x1B[C\x1B(B\x1B[0;1m\x1B[37m\x1B[44mUp/down | q Quit | b Bits/Bytes | +- Update interval (1000ms)\r\x1B[2d\x1B[31m\x1B[40mAddress\x1B[2;39H\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40m192.168.12.37\r\x1B[3d\x1B[K\x1B[4d\x1B[K\x1B[5d\x1B[K\x1B[6d\x1B[K\x1B[1;63H\r\x1B[C\x1B(B\x1B[0;1m\x1B[37m\x1B[44mColor Bandwidth Meter\x1B(B\x1B[0m\x1B[37m\x1B[44m\x1B[K\r\x1B[2d\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40m\x1B[K\x1B[3d \x1B(B\x1B[0;1m\x1B[31m\x1B[40mInterface\x1B[3;22H Receive\x1B[3;41HTransmit\x1B[3;60H Total\x1B[4;3H\x1B[39;49m\x1B[37m\x1B[40menp0s3\x1B[4;22H 0.00 B/s\x1B[41G 59.93 B/s\x1B[60G 59.93 B/s\x1B[5;3H\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40menp0s8\x1B[5;25H82.63 kB/s\x1B[5;45H3.31 kB/s\x1B[5;63H85.94 kB/s\x1B[6;3Hlo\x1B[6;25H87.90 B/s\x1B[6;44H87.90 B/s\x1B[6;62H175.80 B/s\x1B[H'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question