BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / phantomjs-prebuilt / lib / phantom / examples / echoToFile.js

echoToFile.js

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