This is really infuriating. I can't find anywhere in my code where I'm doing anything illegal, but for some reason, calling fork
blows up my program. Here's the code. The relevant portion is in svgToPNG where I call 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
If I take the fork
line out and replace it with something else, everything is hunky dory, but if I leave it in, I get:
> 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
It makes no sense. I don't have any weird illegal unicode character like in this question, I don't believe I have any kind of parse error like in this one... I really don't know what's going on.
Could it be that CoffeeScript is somehow breaking the code? That seems really unlikely, but I don't know.
The error is in your use of fork
. fork
is for spawning Node processes, i.e. foo.js
files. Use spawn
instead.
I figured this out by running a stripped down version of your code, reading an image file and then passing it to your svgToPNG
. The error message starts:
/usr/bin/env:1
(function (exports, require, module, __filename, __dirname) { ELF
The characters rendered in this copy/paste as ELF
are the head characters of my binary /usr/bin/env
file. So node.js
fork
is trying to compile the /usr/bin/env
file. Reviewing the child_process
documentation confirms this. The examples running things like ls
and grep
use spawn
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With