>假设没有一种简单的方法可以从节点 api 获取当前正在运行的进程信息(如果您知道一个好的 api,请告诉我,因为我找不到(,看起来我需要使用像 ps 这样的命令(在 Linux/OSx 中(。
这是我可以在终端上运行的代码,以获取我需要的信息
ps ax | grep "node-webkit.*remote-debugging-port.*nw-apps" | awk '{ print $7 }'
下面是生成相同输出的 Coffee 脚本代码:
it.only 'find_Process', (done)->
if process.platform is 'win32'
done()
else
'ps'.start_Process_Capture_Console_Out 'ax', (data)->
regex = /node-webkit.*remote-debugging-port.*nw-apps/
matches = for line in data.split('n') when regex.exec(line)
line.split(' ')[15]
log matches
done()
所以我的问题是,这是否是用咖啡脚本编写它的更好方法,以及是否有更好的方法以多平台方式实现这一目标(它支持 Windows(
你可以尝试使用 shelljs 执行你的 shellcode,如果这是一个选项。"https://github.com/arturadib/shelljs">
编辑:您可以尝试:
shell.exec('ps aux', function(err, data){
if (err) {
throw err;
}
console.log(data);
})
因为目前似乎没有很好的方法可以做到这一点(2015 年 1 月(