spawn - Unable to make executable that properly communicates with node.js -
i'm testing communication between node.js , executables launched child processes. executable launched within node.js via child_process.spawn() , output monitored node.js. i'm testing capability both on linux , windows oss.
i've spawned tail -f /var/log/syslog , listened output, own executables can't seem write correctly stdout (in whatever form exists when captured node.js).
test code:
#include <iostream> #include <stdio.h> #include <unistd.h> int main() { using namespace std; long x = 1; while (true) { fprintf(stdout, "xtime - %ld\n", x++); usleep(1000000); } } (note: includes may useless; i've not checked them)
stdout output not automatically flushed (at least on *nix) when stdout not tty (even if there newline in output, otherwise newline flushes when stdout tty).
so can either disable stdout buffering entirely via setbuf(stdout, null); or can manually flush output via fflush(stdout);.
Comments
Post a Comment