mirror of
https://github.com/encounter/phantomjs.git
synced 2026-03-30 11:35:11 -07:00
6a79ea7e6d
This is mostly based on Ivan's work, see https://github.com/ariya/phantomjs/pull/153 http://code.google.com/p/phantomjs/issues/detail?id=47
23 lines
577 B
JavaScript
23 lines
577 B
JavaScript
// echoToFile.js - Write in a given file all the parameters passed on the CLI
|
|
var fs = require('fs');
|
|
|
|
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();
|
|
}
|