1
1
mirror of https://github.com/ariya/phantomjs.git synced 2024-09-19 16:48:07 +03:00
phantomjs/examples/echoToFile.js
Ivan De Marino 3807b9dc4d Now, if "fs.open" fails, it throws an exception.
* This is implemented with a javascript-shim
2011-06-28 21:35:27 +01:00

21 lines
552 B
JavaScript

// echoToFile.js - Write in a given file all the parameters passed on the CLI
if (phantom.args.length < 2) {
console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>");
phantom.exit();
} else {
var content = '',
f = null;
for ( i= 1; i < phantom.args.length; ++i ) {
content += phantom.args[i] + (i === phantom.args.length-1 ? '' : ' ');
}
try {
f = fs.open(phantom.args[0], "w");
f.writeLine(content);
} catch (e) {
console.log(e);
}
phantom.exit();
}