【发布时间】:2016-06-29 09:18:41
【问题描述】:
我有以下字符串作为缓冲区(它们是具有随机列值的随机行)。
如何从找到的 ROW 中准确搜索可用 ROW 中的“警告”,如何过滤 PID?
var exec = require('child_process').exec;
exec('TASKLIST /v /FI "IMAGENAME eq python*"', function(a,b,c) {
console.log(b);
// Which PID contain the word : "Warnning" ? can you list them chronologically?
});
输出:
Image Name PID Session Name Session# Mem Usage Status User Name CPU Time Window Title
========================= ======== ================ =========== ============ =============== ================================================== ============ =====================================================
python.exe 9999 RDP-Tcp#10 1 19?556 K Running sun\tpt 0:00:15 Warnning of windows
python.exe 3861 RDP-Tcp#10 1 19?556 K Running sun\tpt 0:00:15 Cancle this crap
python.exe 8080 RDP-Tcp#10 1 19?556 K Running sun\tpt 0:00:15 Warnning of windows
【问题讨论】:
-
您可以使用
var lines = b.split('\r\n');或最好使用var endOfLine = require('os').EOL; var lines = b.split(endOfLine);以行结尾拆分字符串,然后在for 循环中检查行是否包含警告if(lines[i].indexOf('Warning') > -1) console.log(lines[i]);现在要获取pid,您可能需要正则表达式,但我'不擅长那个:(
标签: javascript node.js windows command-line