child_process exec返回一个神秘的错误

时间:2012-07-11 18:03:52

标签: node.js

我有以下代码(从the node docs复制而不是命令本身):

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

该命令似乎执行正常(输出文件在那里),但错误总是“错误:命令失败:”并且没有定义错误(文档说err.code将提供更多信息)。

我做错了什么/忽视?

2 个答案:

答案 0 :(得分:1)

应为error.code

文档混合使用errorerr;它指的是提供给回调的Error对象。

答案 1 :(得分:1)

像我说的那样。几年后。我得到了同样的错误。只是找到可能是错误的结果 - 结帐(https://stackoverflow.com/a/21137820/1211174)。如果你在Windows上有可能你有一些自动运行在cmd上。然后这个自动运行失败了。你得到两个输出。 sterr和stdout