echoToFile.coffee 503 B

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