slimerjs icon indicating copy to clipboard operation
slimerjs copied to clipboard

Add a child_process module

Open laurentj opened this issue 9 years ago • 8 comments

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

laurentj avatar Aug 13 '14 23:08 laurentj

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.

g0morra avatar Aug 14 '14 01:08 g0morra

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

  1. I modified io/*.js to implement CommonJS API for fs, and toolkit/loader.js to support some specificities.
  2. 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...

laurentj avatar Aug 14 '14 11:08 laurentj

May I know is there any development for this? Really hope see child_process module being incorporated into Slimer, thanks for the great work!

mr5iff avatar Sep 17 '14 04:09 mr5iff

+1

kaizhu256 avatar Feb 21 '15 03:02 kaizhu256

+1

masi avatar Mar 20 '15 16:03 masi

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.

masi avatar Apr 17 '15 08:04 masi

Would it be possible to have this feature ?

hadim avatar Jul 06 '15 21:07 hadim

Would be great, as using slimerjs wrapped in casperjs does not allow multiple instances, child processes seems to be the only solution

GerkinDev avatar Dec 04 '16 14:12 GerkinDev