记录phantomjs学习(二)
来源:互联网 发布:java设计模式有几种 编辑:程序博客网 时间:2024/06/10 18:34
System模块
该模块提供了一些与操作系统相关的接口,例如访问操作系统信息、访问系统环境变量、接受命令行参数等等与程序执行相关的系统信息。
1.system.args {String[]}
获取运行phantomjs时传入的所有参数,看一下API的介绍
Queries and returns a list of the command-line arguments. The first one is always the script name, which is then followed by the subsequent arguments.
查找返回一串命令行参数,第一个总为脚本名称,然后携带的参数紧跟其后。
看了网上好多例子,总感觉有些错误。就拿下面的例子来说:
var system = require('system');if (system.args.length === 1) { console.log('Try to pass some args when invoking this script!');} else { system.args.forEach(function (arg, i) { console.log(i + ': ' + arg); });}phantom.exit();
引入模块,创建实例,然后判断其长度 ,当我们在命令行没有输入携带的参数,就只有一个参数,也就是我们的脚本名称,打印出一句话,如果输入,forEach遍历循环打印。正确的输出应该为下图:
2.system.env {Object}
Queries and returns a list of key-value pairs representing the environment variables.(查找返回环境变量的键值对列表)
var system = require('system');var env = system.env;Object.keys(env).forEach(function(key) { console.log(key + '=' + env[key]);});
3.system.os
Read-only. An object providing information about the operating system, including architecture, name, and version. For example:
获取操作系统信息,返回一个简单对象,这个对象有3个属性: architecture:架构,如“32bit”; name:操作系统名称; version:操作系统版本。
4.system.pid Number获取当前进程的pid
5.system.platform String永远返回 ‘phantomjs’
- 记录phantomjs学习(二)
- 记录phantomjs学习(一)
- 记录phantomjs学习(三)
- AcegiSecurity学习记录(二)
- DB2学习记录(二)
- DB2学习记录(二)
- Magento 学习记录(二)
- Android学习记录(二)
- perl学习记录(二)
- JS学习记录(二)
- django学习记录(二)
- Linux学习记录(二)
- Python 学习记录(二)
- JavaScript学习记录(二)
- swift 学习记录(二)
- Git学习记录---------(二)
- APUE学习记录(二)
- Android学习记录(二)
- CentOS 7 firewalld使用简介
- output buffering vs string concatenation / ob vs 拼接字符串
- Hibernate学习笔记 查询简介
- 一些有用的小程序资料
- 【Awesome Power Mode】
- 记录phantomjs学习(二)
- java future
- 检测用户有无操作
- Scala中最常用数据结构Map和Tuple
- git学习
- 使用RecyclerView加载不出数据的原因可能有:
- CentOS 7.2 下安装 Docker 1.12.3 版的详细方法
- 网吧升级机房问题集
- LeetCode-399. Evaluate Division-思路详解-C++