How to return the data in the child process generated by spawn to the node js main program in node js

for example, program:

< H1 > include < stdio.h > < / H1 > < H1 > include < unistd.h > < / H1 >

int main () {
int cntr = 0;
while (1) {
sleep (1);
cntrPP;
printf ("cntr =% dn", cntr);
}

After

}
is compiled into a getpsdata file,
then passes through:
var spawn = require ("child_process"). Spawn;
var ps = spawn (". / getpsdata", {stdio: ["pipe"," pipe", "pipe"]});

if (ps.stdout! = = null) {

ps.stdout.on( "data" , function(data) {
  console.log( "data" , data.toString());
});

} else {

console.log(ps.stdout);

}
/ / ps.stdout.on ("data", function (data) {
/ / console.log (" data", data.toString ());
/ /});

if (ps.stderr! = = null) {

ps.stderr.on( "data" , function(data) {
  console.log( "data" , data.toString());
});

} else {

console.log(ps.stderr);

}

/ / ps.stderr.on ("data", function (data) {
/ / console.log (" error", data.toString ());
/ /});

ps.on ("close", function (code) {
console.log (" close", code);
});

ps.on ("exit",function (code) {

)
console.log( "exit" , code);

});

ps.on ("error", function (code) {
console.log (" error", code);
});
I want to send the printed data in getpsdata to the main program of node. What should I do?

Jun.29,2021

I also encountered this problem, it is not untransferable, it still seems to write data to stdio, only at the end of the subroutine, the data event will be activated, and then you will be from

ps.stdout.on( 'data' , function(data) {
  console.log( 'data' , data.toString());
});

print out the data, and if the subroutine keeps running, the data event will not be activated.
I don't know why.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5f0a1-457f3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5f0a1-457f3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?