我遇到了一个晦涩难懂的错误: ENOENT。这是输出。
converting SVG to a PNG
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)这是代码。检查打印语句,它似乎就在调用child.spawn之前发生。
child = require 'child_process'
svgToPNG = (svg, reply, log) ->
# set up a child process to call convert svg: png:-
log "converting SVG to a PNG"
convert = child.spawn 'convert', ['svg:', 'png:-']
convert.stderr.on 'data', (data) ->
log data.toString()
convert.stdout.end data
return reply "error occurred"
# create buffer that output will be piped into
res = ""
# pipe this process' stdout into res
convert.stdout.pipe res
# pipe svg into the process and close its input, startin the process
convert.stdin.end svg
# call reply with the res as content
log "OK done converting to a PNG, replying"
reply res从命令行调用convert可以很好地工作。我不确定这为什么会失败。
发布于 2013-10-04 05:52:29
当您在shell中键入convert时,shell将通过搜索PATH环境变量中的目录来查找convert可执行文件的完整路径。child_process.spawn不会这样做。因此,要么使用convert的绝对路径,要么使用/usr/bin/env程序,该程序将像交互式shell一样搜索该路径。如果您使用/usr/bin/env,它将成为您的命令,convert将成为参数1,convert的其余参数紧随其后。
https://stackoverflow.com/questions/19169607
复制相似问题