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);
}
}
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?