slimerjs
slimerjs copied to clipboard
Add a child_process module
PhantomJS has a module child_process to launch an external program and to communicate with it via stdin / stdout / stderr.
We could use the child_process module from the addons sdk
I've got a working webpage.childProcess() based on the Addons SDK. Would you be interested in a contribution?
Based on what's easy and already in subprocess.js, how about:
webpage.childProcess(command, arguments, environVars, stdin, mergeStderr)
@param {String} command Path to the executable you want to run
@param {Array} [arguments] Array of cli args
@param {Array} [environVars] Environment vars you want to set, e.g. setting DISPLAY
@param {String} [stdin] Stdin to pipe into command
@param {Boolean} [mergeStderr] If true, stderr is merged into stdout
@returns {Object} with properties exitCode, stdout, stderr
You can also pass functions into subprocess.call() that you can apply to stdout and stderr, but it's probably easier just to return stdout and stderr as string properties of the returned object, and then the user can do whatever they like with the output in their Slimer script.
The API should be exposed as a module, like in PhantomJS, not as a method of webpage. In theory, we just have to add a mapping here.
But this is a mapping to our own version of the addons-sdk. We have our own version of the SDK because
- I modified io/*.js to implement CommonJS API for fs, and toolkit/loader.js to support some specificities.
- the SDK is bundled into Gecko only since Gecko 21. And SlimerJS is supposed to be compatible with Gecko 17+.
We could forget Gecko version under 21, rely on the embedded SDK, but we should do something for io/*.js (specific mapping?)? And there would be an other problem: child_process.js appeared only since Gecko 28 or 29... And I would like SlimerJS to be compatible with older versions.
So we should import child_process.js and all of its dependencies into our own addons SDK version. And verify that it is compatible with older version of Gecko...
May I know is there any development for this? Really hope see child_process module being incorporated into Slimer, thanks for the great work!
+1
+1
What is the point of supporting older versions of Gecko? I also hate to break things, but is anyone really trying to run SlimerJS on a years old version of xulrunner? How about adding the functionality only for more recent versions, perhaps using the API addes in 28/29. Anyone using the child_process module will "simply" get a nice errror message.
Would it be possible to have this feature ?
Would be great, as using slimerjs wrapped in casperjs does not allow multiple instances, child processes seems to be the only solution