echoToFile.js 601 B

123456789101112131415161718192021222324
  1. // echoToFile.js - Write in a given file all the parameters passed on the CLI
  2. "use strict";
  3. var fs = require('fs'),
  4. system = require('system');
  5. if (system.args.length < 3) {
  6. console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>");
  7. phantom.exit(1);
  8. } else {
  9. var content = '',
  10. f = null,
  11. i;
  12. for ( i= 2; i < system.args.length; ++i ) {
  13. content += system.args[i] + (i === system.args.length-1 ? '' : ' ');
  14. }
  15. try {
  16. fs.write(system.args[1], content, 'w');
  17. } catch(e) {
  18. console.log(e);
  19. }
  20. phantom.exit();
  21. }