     if err.errno is 'ENOENT'
       child.error = procNotFoundError(err, cmd).stack
     child.rawProcess.kill()
-
-  process.on 'exit', ->
-    try child.rawProcess.kill()
-    catch err
-      console.error err.stack
-
-  process.on 'uncaughtException', (error) ->
-    try child.rawProcess.kill()
-    catch err
-      console.error err.stack
-    throw error
 
   child
 

    launchArguments: args
    workingDirectory: spawnOpts.cwd

  child.readLog = (callback) ->
    fs.readFile logPath, (error, data) ->
      return callback(error) if error?

{spawn} = require 'child_process'
fs = require 'fs'


killAllProcs = (procs) ->
  procs.forEach (proc) ->
    try
      proc.rawProcess.kill()
    catch err
      console.error err.stack
  procs = []

allProcs = []
registered = false
registerUncaughtHandler = (proc) ->
  allProcs.push(proc)

  if !registered
    process.on 'uncaughtException', (error) ->
      killAllProcs(allProcs)
      throw error

    process.on 'exit', ->
      killAllProcs(allProcs)

    registered = true


procNotFoundError = (error, cmd) ->
  error.message = "Unable to find #{cmd}"
