baldmark
baldmark

Reputation: 707

child_process exec returning a mysterious error

I have the following code (copied from the node docs apart from the command itself) :

var util = require('util'),
    exec = require('child_process').exec,
    child,
    command = 'libreoffice --headless -convert-to pdf mysourcefile.doc -outdir /tmp';
child = exec(command,
           function (error, stdout, stderr) {
              if (error !== null) {
                 console.log(error);
                 return;
              }
           );

The command appears to be executing fine (output file is there) but error is always "Error: Command failed:" and err is not defined (the docs say err.code will give more information).

What am I doing wrong / overlooking?

Upvotes: 0

Views: 3622

Answers (2)

oak
oak

Reputation: 3028

like i say . years after. i got the same error. just find what can be the error - checkout (https://stackoverflow.com/a/21137820/1211174). if you are on windows there is a chance that you have someauto run on cmd. and then this autorun failed. and you get both output. sterr and stdout

Upvotes: 1

baldmark
baldmark

Reputation: 707

It should be error.code.

The docs mix the use of error and err; it refers to the Error object provided to the callback.

Upvotes: 1

Related Questions