echoToFile.js 591 B

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