首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coffeescript意外令牌非法,但不应该有任何非法行为

Coffeescript意外令牌非法,但不应该有任何非法行为
EN

Stack Overflow用户
提问于 2013-10-03 23:06:05
回答 1查看 1.2K关注 0票数 7

这真是令人恼火。在我的代码中,我找不到任何不合法的地方,但出于某种原因,调用fork会破坏我的程序。这是密码。相关部分在svgToPNG中,我在这里调用fork

代码语言:javascript
复制
{fork} = require 'child_process'
{Coral} = require 'coral'

svgToPNG = (svg, reply, log) ->
  log "converting SVG to a PNG"
  # set up a child process to call convert svg: png:-
  convert = fork '/usr/bin/env', ['convert', 'svg:', 'png:-']
  log "Spawned child process running convert, pid " + convert.pid
  # set up behavior when an error occurs
  convert.stderr.on "data", ->
    log "Error occurred while executing convert"
    reply "error"
  # set up behavior for when we successfully convert
  convert.stdout.on "data", ->
    log "Successful conversion! :)"
    log "here's the data: " + data
    reply data
  # pipe the SVG into the stdin of the process (starting it)
  convert.stdin.end svg

如果我把fork线取出来,用其他东西替换它,那么一切都是很棒的,但是如果我把它放在里面,我就得到:

代码语言:javascript
复制
> coffee src/coral_client.coffee
finished doing conversion to svg!
converting SVG to a PNG
Spawned child process running convert, pid 60823

/usr/bin/grep:1
(function (exports, require, module, __filename, __dirname) { ����
                                                              ^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

这没有任何意义。我没有像this question那样奇怪的非法unicode字符,我不相信我有任何像this one那样的解析错误.我真的不知道怎么回事。

难道是CoffeeScript以某种方式破坏了代码吗?这看起来不太可能,但我不知道。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-04 05:31:45

错误发生在您使用fork时。fork用于生成节点进程,即foo.js文件。使用spawn代替。

我通过运行一个简化的代码版本,读取一个图像文件,然后将它传递给您的svgToPNG来解决这个问题。错误消息开始:

代码语言:javascript
复制
/usr/bin/env:1
(function (exports, require, module, __filename, __dirname) { ELF

此复制/粘贴中呈现为ELF的字符是二进制/usr/bin/env文件的头字符。因此,node.js fork试图编译/usr/bin/env文件。查看child_process文档证实了这一点。运行像lsgrep这样的东西的例子使用spawn

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

https://stackoverflow.com/questions/19170607

复制
相关文章

相似问题

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