jashkenas/coffee-script — pull request #2119 by shlevy (2012-02-13 00:45:16+00:00)
Title: Bug when directly running a script containing child_process.fork

Against current master, given this script as index.coffee:

fork = require('child_process').fork

if process.send?
process.send "Done"
process.exit()
else
child = fork __filename
child.on "message", (msg) ->
console.log msg
process.exit()

we have:

$ coffee index.coffee
env: node: No such file or directory

and:

$ coffee -c index.coffee; node index.js
Done

The problem here is that https://github.com/joyent/node/blob/3f43b1c039727e12c7a27fb31010aa309a4a35d8/lib/child_process.js#L209 clears env before spawning a new coffeescript process, and so the shebang in the coffee executable (#!/usr/bin/env node) fails because PATH is unset. This env-clearing behavior in absence of a specified 'env' object is inconsistent with the other child_process methods, so I will file an issue with node to check if this is a bug, but this PR will fix the issue in the meantime.