-
-
Save clochix/6882184 to your computer and use it in GitHub Desktop.
// (…) | |
var childProcess; | |
try { | |
childProcess = require("child_process"); | |
} catch (e) { | |
this.log(e, "error"); | |
} | |
if (childProcess) { | |
childProcess.execFile("/bin/bash", ["mycommand.sh", args1, args2, args3], null, function (err, stdout, stderr) { | |
this.log("execFileSTDOUT:", JSON.stringify(stdout), 'debug'); | |
this.log("execFileSTDERR:", JSON.stringify(stderr), 'debug'); | |
}); | |
this.log("Done", "debug"); | |
} else { | |
this.log("Unable to require child process", "warning"); | |
} |
@mickaelandrieu what kind of API would you like to add to CasperJS? I'm finding the PhantomJS one good enough.
https://github.com/ariya/phantomjs/blob/master/src/modules/child_process.js she's not documented :/ But you're right we don't need more thant Phantomjs'one
thanks for the script . my casperjs file is located in c://wamp/www what i want is to execute
"myexefile.exe -l username -p password -c myfile.txt [-t 10000]"
but there is no doc available or example . i just want to execute the above command and store the responce in var myvalue in casperjs plese help
I don't really understand how to incorporate the provided code into a Jasper test (using Jasper's promises, I guess). Would you mind providing an example wrapped inside a casper.then()
?
What is the equivalent for slimerjs? I get the following error when I run the same script that passes with phantomjs under slimerjs.
FAIL Error: Module: Can not resolve "child_process" module required by main located at file:///usr/local/lib/node_modules/casperjs/bin/bootstrap.js
type: uncaughtError
file: functionalTestsWIP.js
error: {}
stack: not provided
any chance you know how to get the standout in casper.then?
Sample code:
casper.then(function(){
childProcess.execFile("/bin/bash", ["mycommand.sh", args1, args2, args3], null, function (err, stdout, stderr) {
this.log("execFileSTDOUT:", JSON.stringify(stdout), 'debug');
this.log("execFileSTDERR:", JSON.stringify(stderr), 'debug');
});
});
casper.then(function(){});
I cannot get any stdout or stderr from the callback by running a bash script. but if I do simple commands like ls -l /usr
, i can get the output.
Maybe we can add this in the Casper API ? It would be useful !
https://code.google.com/p/phantomjs/source/browse/examples/child_process-examples.js?r=f52044cd3106266aa8efc1fae05e8c923315a5e5
What's the difference between spawn & execFile ?