2011-06-14 11:28:51 +01:00
|
|
|
// echoToFile.js - Write in a given file all the parameters passed on the CLI
|
2012-01-15 00:13:26 +09:00
|
|
|
var fs = require('fs'),
|
|
|
|
|
system = require('system');
|
2011-06-14 11:28:51 +01:00
|
|
|
|
2012-01-15 00:13:26 +09:00
|
|
|
if (system.args.length < 3) {
|
2011-06-14 11:28:51 +01:00
|
|
|
console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>");
|
2012-05-16 09:37:26 +02:00
|
|
|
phantom.exit(1);
|
2011-06-14 11:28:51 +01:00
|
|
|
} else {
|
|
|
|
|
var content = '',
|
|
|
|
|
f = null;
|
2012-01-15 00:13:26 +09:00
|
|
|
for ( i= 2; i < system.args.length; ++i ) {
|
|
|
|
|
content += system.args[i] + (i === system.args.length-1 ? '' : ' ');
|
2011-06-14 11:28:51 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-28 21:35:27 +01:00
|
|
|
try {
|
2012-01-15 00:13:26 +09:00
|
|
|
f = fs.open(system.args[1], "w");
|
2011-06-14 11:28:51 +01:00
|
|
|
f.writeLine(content);
|
2012-02-29 07:53:12 -08:00
|
|
|
f.close();
|
2011-06-28 21:35:27 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e);
|
2011-06-14 11:28:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
phantom.exit();
|
2011-09-08 09:55:50 -07:00
|
|
|
}
|