Created
October 8, 2013 09:37
-
-
Save clochix/6882184 to your computer and use it in GitHub Desktop.
Sample code to call a shell script from CasperJS
This file contains 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
// (…) | |
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"); | |
} |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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