Files
phantomjs/examples/echoToFile.coffee
T
Ivan De Marino 3807b9dc4d Now, if "fs.open" fails, it throws an exception.
* This is implemented with a javascript-shim
2011-06-28 21:35:27 +01:00

18 lines
478 B
CoffeeScript

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