这真是令人恼火。在我的代码中,我找不到任何不合法的地方,但出于某种原因,调用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如果我把fork线取出来,用其他东西替换它,那么一切都是很棒的,但是如果我把它放在里面,我就得到:
> 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以某种方式破坏了代码吗?这看起来不太可能,但我不知道。
发布于 2013-10-04 05:31:45
错误发生在您使用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_process文档证实了这一点。运行像ls和grep这样的东西的例子使用spawn。
https://stackoverflow.com/questions/19170607
复制相似问题