Created
November 20, 2015 15:27
-
-
Save ryohey/c0e199c20f57b2fa609a to your computer and use it in GitHub Desktop.
Wrapping a child process as a class and communicate in electron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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