Comparing version 0.1.0 to 0.1.1
@@ -0,1 +1,6 @@ | ||
## 2016-05-05 | ||
- Publish 0.1.1 update table-parser to 0.1.1 | ||
- Integrate with Travis-CI linux / mac is fully tested now | ||
- Manually test on Win10 and Win7 | ||
## 2016-04-26 | ||
@@ -2,0 +7,0 @@ - Publish 0.1.0 update table-parser to 0.1.0 |
var ChildProcess = require('child_process'); | ||
var IS_WIN = process.platform === 'win32'; | ||
var TableParser = require( 'table-parser' ); | ||
/** | ||
* End of line. | ||
* Basically, the EOL should be: | ||
* - windows: \r\n | ||
* - *nix: \n | ||
* But i'm trying to get every possibilities covered. | ||
*/ | ||
var EOL = /(\r\n)|(\n\r)|\n|\r/; | ||
var SystemEOL = require( 'os' ).EOL; | ||
@@ -15,5 +24,5 @@ /** | ||
var Exec = module.exports = exports = function( args, callback) { | ||
if (Array.isArray(args)) { | ||
args = args.join(' '); | ||
} | ||
if (Array.isArray(args)) { | ||
args = args.join(' '); | ||
} | ||
@@ -29,3 +38,3 @@ // windows 下直接通过exec方法来wmic process get没有stdout,因此通过调用CMD的方法来做 | ||
CMD.stdout.on('data', function (data) { | ||
stdout = stdout.concat( data.toString().split('\r\n') ); | ||
stdout += data.toString(); | ||
}); | ||
@@ -46,6 +55,7 @@ | ||
var beginRow; | ||
stdout = stdout.split( EOL ); | ||
// 寻找到数据的第一行(标题行) | ||
stdout.forEach(function( out, index ){ | ||
if( typeof beginRow == 'undefined' && out.indexOf( 'CommandLine' ) === 0 ){ | ||
if( out && typeof beginRow == 'undefined' && out.indexOf( 'CommandLine' ) === 0 ){ | ||
beginRow = index; | ||
@@ -59,9 +69,3 @@ } | ||
// FS.writeFileSync( __dirname + '/log.' + Date.now(), stdout.join('')); | ||
// 去掉第一行和第二行,分别为System Idle Process 和 System,它们有大量字段丢失,影响结果 | ||
var stdoutTmp = stdout.join( '' ).split( '\n'); | ||
stdoutTmp.splice( 1, 2 ); | ||
callback( stderr, stdoutTmp.join( '\n') || false ); | ||
callback( stderr, stdout.join( SystemEOL ) || false ); | ||
}); | ||
@@ -99,8 +103,12 @@ | ||
exports.lookup = function(query, callback) { | ||
var exeArgs = query.psargs || []; | ||
/** | ||
* add 'l' as default ps arguments, since the default ps output in linux like "ubuntu", wont include command arguments | ||
*/ | ||
var exeArgs = query.psargs || [ 'l' ]; | ||
var filter = {}; | ||
var idList; | ||
// Lookup by PID | ||
if ( query.pid ) { | ||
// Lookup by PID | ||
if ( query.pid ) { | ||
@@ -113,3 +121,3 @@ if( Array.isArray( query.pid ) ){ | ||
} | ||
// Cast all PIDs as Strings | ||
@@ -119,6 +127,6 @@ idList = idList.map( function( v ){ | ||
} ); | ||
} | ||
} | ||
if( query.command ){ | ||
@@ -205,3 +213,3 @@ filter[ 'command' ] = new RegExp( query.command ); | ||
function parseGrid( output ) { | ||
if ( !output ) { | ||
if ( !output ) { | ||
return output; | ||
@@ -208,0 +216,0 @@ } |
{ | ||
"name": "ps-node", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A process lookup utility", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha -t 0 -R spec test/test.js" | ||
"test": "node ./node_modules/mocha/bin/mocha -t 0 -R spec test/test.js" | ||
}, | ||
@@ -21,3 +21,3 @@ "keywords": [ | ||
"dependencies": { | ||
"table-parser": "^0.1.0" | ||
"table-parser": "^0.1.1" | ||
}, | ||
@@ -24,0 +24,0 @@ "license": "MIT", |
@@ -1,2 +0,2 @@ | ||
# ps | ||
# ps [![Build Status](https://travis-ci.org/neekey/ps.svg)](https://travis-ci.org/neekey/ps) | ||
@@ -13,2 +13,16 @@ A Node.js module for looking up running processes. This module uses [Table-Parser](https://github.com/neekey/table-parser) to parse the output. | ||
## How Does It Work | ||
This module uses different tools to get process list: | ||
- Linux / Mac: use `ps` command. Since the default result from shell command `$ ps` will not contain "command arguments" in linux like "ubuntu", ps-node add arguments `l` as default. Which means, the default value for option `psargs` is `l`. | ||
- Win: use command `wmic process get ProcessId,CommandLine` through "cmd", more info about wmic is [here](https://social.technet.microsoft.com/Forums/windowsserver/en-US/ab6c7e6e-4ad4-4237-bab3-0349cd76c094/wmic-command-line-utilities?forum=winservercore). | ||
## Compatibility | ||
- Should work great in most *nix system. | ||
- Should work on Win10/7 more system versions need to be test. | ||
Any compatibility issue is welcomed. | ||
## Usage | ||
@@ -131,3 +145,2 @@ | ||
- [Non-english characters may cause parse error](https://github.com/neekey/table-parser). | ||
- [This module may not work on Windows](https://github.com/neekey/ps/issues/10). | ||
- [multiple-bytes characters may cause parse error](https://github.com/neekey/table-parser). |
@@ -6,3 +6,3 @@ var PS = require( '../index' ); | ||
var serverPath = Path.resolve( __dirname, './server_for_test.js' ); | ||
var serverPath = Path.resolve( __dirname, './node_process_for_test.js' ); | ||
var child = CP.fork( serverPath ); | ||
@@ -25,3 +25,3 @@ var pid = child.pid; | ||
it( 'by command & arguments', function( done ){ | ||
PS.lookup({ command: '.*node.*', arguments: serverPath }, function( err, list ){ | ||
PS.lookup({ command: '.*(node|iojs).*', arguments: 'node_process_for_test' }, function( err, list ){ | ||
assert.equal( list.length, 1 ); | ||
@@ -28,0 +28,0 @@ assert.equal( list[0].pid, pid ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
13904
10
240
145
2
Updatedtable-parser@^0.1.1