Hadoop Streaming: works on cluster with linux command, but not working coffeescript

I am having trouble while running my job on hadoop cluster. The job runs well on local machine and on cluster if i replace my coffeescript, it runs well with normal /bin/cat as mapper and reducer. But stops while running with my coffeescript code which reads input from stdin using process.stdin.

Sample coffeescript code:

  #!/usr/bin/env PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" map.coffee

  stdin = process.openStdin()

  stdout = process.stdout

  stdin.setEncoding 'utf8'

  stdin.on 'data', (data) ->

    return unless data?
    input += data
    stdout.write "Input started reading"
    while input.match /\r?\n/
      stdout.write "Logs: #{RegExp.rightContext}"
      input = RegExp.rightContext
      proc RegExp.leftContext