我想查一查IP列表,然后查grep country。
我有:
const { spawn } = require('child_process')
const ip_list = [
'192.168.1.1',
'192.168.1.2',
'192.168.1.3'
]
const process = spawn('whois', ip_list)
process.stdout.on('data', (data) => {
console.log(data)
}),这相当于运行whois ip1 ip2 ip3 ...。
但我想要的相当于运行whois ip1 ip2 ip3 ... | grep country
在Node怎么做?
我尝试在ip_list的末尾添加"grep country“或仅仅”grep country“作为args,但这给了我一个查询错误。
发布于 2021-02-21 16:32:11
好的,所以我必须将ip_list转换成所有in的字符串,用空格分隔,然后使用Using a pipe character | with child_process spawn中提到的方法。
const str1 = ip_list.join(' ')
const process = spawn('sh', ['-c', 'whois ' + str1 + ' | grep country'])https://stackoverflow.com/questions/66304109
复制相似问题