Reputation: 679
I'm trying to pass args to casperjs so that I can take advantage of environment variables. For some reason, I'm not able to access them from the casper script (crawl.js). I can confirm that if I call crawl.js from the CLI with the args, I am able to successfully access them.
I haven't been able to confirm the syntax, as the docs simply say an array for args.
var execFile = require('child_process').execFile;
var child = execFile('casperjs',
['crawl.js'], [
"--MM_Report_URL='"+process.env.MM_Report_URL+"'",
"--MM_login='"+process.env.MM_login+"'",
"--MM_password='"+process.env.MM_password+"'"
]);
Upvotes: 0
Views: 500
Reputation: 679
I was able to figure it out and it was a dumb mistake on my part. I've pasted the correct syntax below.
Notice that I've placed the file and the other arguments into the same array. This is because crawl.js is an argument for the file casperjs (an executable).
var execFile = require('child_process').execFile;
var child = execFile('casperjs',
[
'crawl.js'
'--MM_Report_URL='+process.env.MM_Report_URL,
'--MM_login='+process.env.MM_login,
'--MM_password='+process.env.MM_password
]);
Upvotes: 1