Das ist wirklich ärgerlich. Ich kann nirgends in meinem Code finden, wo ich etwas illegal mache, aber aus irgendeinem Grund, ruft fork
mein Programm in die Luft. Hier ist der Code. Der relevante Teil ist in svgToPNG, wo ich fork
anrufen.Coffeescript unerwartetes Token ILLEGAL, aber es sollte nichts illegales sein
{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
Wenn ich nehme die fork
Linie aus und ersetzen sie durch etwas anderes, ist alles bester Ordnung, aber wenn ich es verlassen in, erhalte ich:
> 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
Es macht keinen Sinn. Ich habe keine seltsame illegale Unicode-Charakter wie in this question, ich glaube nicht, ich habe irgendeine Art von Parse-Fehler wie in this one ... Ich weiß wirklich nicht, was los ist.
Könnte es sein, dass CoffeeScript den Code irgendwie bricht? Das scheint wirklich unwahrscheinlich, aber ich weiß es nicht.
Welche Datei konvertieren Sie? Sollte es nicht 'convert svg: somefilename png: -' sein? – hpaulj
Haben Sie versucht, dieses Skript zu kompilieren, und führen Sie dann die 'js' mit' node' aus? Wenn das 'js' gut aussieht, dann ist das Problem nicht bei coffeescript. – hpaulj
@hpaulj Die Svg-Datei wird in die Standardeingabe des Prozesses geleitet. –