首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在node.js中遇到环境问题

在node.js中遇到环境问题
EN

Stack Overflow用户
提问于 2013-10-04 05:32:50
回答 1查看 649关注 0票数 0

我遇到了一个晦涩难懂的错误: ENOENT。这是输出。

代码语言:javascript
复制
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之前发生。

代码语言:javascript
复制
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可以很好地工作。我不确定这为什么会失败。

EN

回答 1

Stack Overflow用户

发布于 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的其余参数紧随其后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19169607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档