lim*_*imp 7 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 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
这没有道理.我没有任何奇怪的非法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_process文档证实了这一点。ls运行诸如和grepuse之类的示例spawn。
| 归档时间: | 
 | 
| 查看次数: | 1092 次 | 
| 最近记录: |