0

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 ?

Lucasvw
  • 157
  • 1
  • 9
  • One tip: don't call your child process variable `process`, there is already a "global" `process` object and that could make things confusing (and could cause hard to track down bugs). – mscdex Sep 30 '16 at 09:27
  • Did you try changing your `'exit'` event handler to a `'close'` event handler? You should almost always use `'close'` because that is when both the child process has exited *and* when no more data will arrive on either of the stdout or stderr streams. Data can still be received after the `'exit'` event. – mscdex Sep 30 '16 at 09:30

1 Answers1

0

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.

Community
  • 1
  • 1
Lucasvw
  • 157
  • 1
  • 9