Lucasvw Lucasvw - 1 month ago 6
Node.js Question

Spawned Node (.exe) process doesnt catch stderr messages

So I am having some trouble with Node and spawning processes here..

I am spawning an external exe process as such:

var writeStream = fs.createWriteStream(logPath);

writeStream.write(new Date().toString() + " : " + type + " : LOG STARTED ");

var process = cp.spawn(fileNameExecutable, paramArray, {
cwd: pathToExecutable
});


process.stdout.on('data', function (data) {
writeStream.write(new Date().toString() + " : " + type + " stdout : " + string);
});

var errorLog = "";
process.stderr.on('data', function (data) {
errorLog += data;
writeStream.write(new Date().toString() + " : " + type + " stderr : " + data );
});

process.on("exit", function (exitcode) {
if (exitcode === 1) {
done(new Error(errorLog));
} else {
done();
}
});


Problem is that this code only catches the stdout of the process for some reason.. Everything which is outputted over stderr doesnt arrive at the listener.

I know there is stderr output because when I am running the same command over commandline and attach

> stdout.txt 2> stderr.txt


to redirect both streams into a textfile, I am getting messages in both my stderr.txt and stdout.txt

Does anybody have any ideas why the stderr listener is not getting these messages in my JS code ?

Answer

Ok, so I finally found the solution..

The application is a QT based C++ app with the following behavior:

Where is located the qDebug qWarning qCritical and qFatal log by default on Qt?

In short: by setting QT_LOGGING_TO_CONSOLE to 1 before node startup it gets logged correctly.

Comments