浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

phantomjs/examples/echoToFile.js at master · ariya/phantomjs

// echoToFile.js - Write in a given file all the parameters passed on the CLI
var fs = require('fs'),
    system = require('system');
if (system.args.length < 3) {
    console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>");
    phantom.exit();
} else {
    var content = '',
        f = null;
    for ( i= 2; i < system.args.length; ++i ) {
        content += system.args[i] + (i === system.args.length-1 ? '' : ' ');
    }
    
    try {
        f = fs.open(system.args[1], "w");
        f.writeLine(content);
        f.close();
    } catch (e) {
        console.log(e);
    }
    phantom.exit();
}
posted on 2012-05-06 22:46  lexus  阅读(272)  评论(0编辑  收藏  举报