Javascript Coffeescript意外代币非法,但不应存在';这不是什么违法的事

Javascript Coffeescript意外代币非法,但不应存在';这不是什么违法的事,javascript,coffeescript,Javascript,Coffeescript,这真是令人气愤。我在代码中找不到任何非法操作的地方,但出于某种原因,调用fork会破坏我的程序。这是密码。相关部分在svgToPNG中,我在这里调用fork {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 s

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

{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
如果我拿出
叉子
行,换上其他东西,一切都很好,但如果我把它放进去,我会得到:

> 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
这毫无意义。我没有任何像中这样奇怪的非法unicode字符,我不相信我有任何像中这样的解析错误。。。我真的不知道发生了什么事


可能是CoffeeScript以某种方式破坏了密码吗?这似乎不太可能,但我不知道。

错误在于您使用了
fork
fork
用于生成节点进程,即
foo.js
文件。改用
spawn

我通过运行代码的精简版本,读取图像文件,然后将其传递给
svgToPNG
来解决这个问题。错误消息将启动:

/usr/bin/env:1
(function (exports, require, module, __filename, __dirname) { ELF

此复制/粘贴中呈现为
ELF
的字符是我的二进制
/usr/bin/env
文件的头字符。因此,
node.js
fork
正在尝试编译
/usr/bin/env
文件。查看
child\u流程
文档证实了这一点。运行诸如
ls
grep
之类的示例使用
spawn

您正在转换什么文件?是否应该是
convert svg:somefilename png:-
?您是否尝试编译此脚本,然后使用
节点运行
js
?如果
js
看起来不错,那么问题不在于coffeescript。@hpaulj svg文件通过管道传输到进程的标准输入中。@hpaulj当我编译到javascript并使用
节点运行它时,我会遇到同样的错误。如果将
{
中的所有空格删除到下一个非空格字符,会发生什么情况?(在
(函数(导出、要求、模块、文件名、目录名){����)太好了!非常感谢!