Skip to content

Instantly share code, notes, and snippets.

@ryohey
Created November 20, 2015 15:27
Show Gist options
  • Select an option

  • Save ryohey/c0e199c20f57b2fa609a to your computer and use it in GitHub Desktop.

Select an option

Save ryohey/c0e199c20f57b2fa609a to your computer and use it in GitHub Desktop.
Wrapping a child process as a class and communicate in electron
remote = global.require "remote"
child_process = remote.require "child_process"
class Foo
start: ->
@child = child_process.spawn "fooProgram", [barArgument]
doFooBar: (arg1, callback) ->
@child.stdin.write arg1
@child.stdout.once "data", (chunk) ->
callback null, chunk.toString()
@child.stderr.once "data", (chunk) ->
callback chunk.toString(), null
foo = new Foo
foo.start()
foo.doFooBar (err, result) ->
console.log err, result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment