phantomjs/examples/echoToFile.coffee

21 lines
522 B
CoffeeScript

# echoToFile.coffee - Write in a given file all the parameters passed on the CLI
fs = require 'fs'
system = require 'system'
if system.args.length < 3
console.log "Usage: echoToFile.coffee DESTINATION_FILE <arguments to echo...>"
phantom.exit 1
else
content = ""
f = null
i = 2
while i < system.args.length
content += system.args[i] + (if i == system.args.length - 1 then "" else " ")
++i
try
f = fs.open(system.args[1], "w")
f.writeLine content
catch e
console.log e
phantom.exit()