node.js exec无法找到文件

时间:2014-03-12 14:15:45

标签: node.js

我正在尝试使用GraphicsMagick获取有关图像的一些信息,使用node.js Exec执行子进程,这里是代码:

var execGm= require('child_process').execFile;
var child;
child = execGm('gm identify /path/to/my/image/file/test.tif',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
  console.log('exec error: ' + error);
  }
});

在节点日志中我得到了这个结果:stdout: stderr: exec error: Error: spawn ENOENT。 如果我直接从我的MAC控制台执行命令gm identify /path/to/my/image/file/test.tif,我会从图像中获取所有信息。在我看来,gm可执行文件找不到该文件,因为child = execGm('gm',etc....节点返回此日志:

  stdout: GraphicsMagick 1.3.19 2013-12-31 Q8 http://www.GraphicsMagick.org/
  Copyright (C) 2002-2013 GraphicsMagick Group.
  Additional copyrights and licenses apply to this software.
  See http://www.GraphicsMagick.org/www/Copyright.html for details.
  Usage: gm command [options ...]

  Where commands include: 
  batch - issue multiple commands in interactive or batch mode
  benchmark - benchmark one of the other commands
  compare - compare two images
  composite - composite images together
  conjure - execute a Magick Scripting Language (MSL) XML script
  convert - convert an image or sequence of images
  help - obtain usage message for named command
  identify - describe an image or image sequence
  mogrify - transform an image or sequence of images
  montage - create a composite image (in a grid) from separate images
  time - time one of the other commands
  version - obtain release version

  stderr: 
  exec error: Error: Command failed: `

我尝试了几条路径,但没有路线......

1 个答案:

答案 0 :(得分:0)

根据@alexeyten的建议,缺少一些格式正确的参数,

child = execGm('gm', [ 'identify', '/path/to/my/image/file/test.tif'], ...