NodeJs Child_Process.exec找不到命令

时间:2019-10-01 02:19:21

标签: node.js bash ubuntu-18.04 child-process arp

我在npm中使用mz / child_process来获取有关ARP表的信息,这在macOS上有效,因此我在MacBook中使用Ubuntu 18.04 LTS虚拟机,因此请测试命令。

var cp = require('mz/child_process')
   cp.exec('arp -a').then(function (stdout) {
   console.log(stdout)
})

我必须使用以下命令手动安装arp

sudo apt-get install net-tools

但是当我在Ubuntu中执行cp.exec('arp -a')时,我得到:

  

错误:/ bin / sh:1:arp:未找到

路径正常,在控制台中我可以毫无问题地运行arp -a,而arp在哪里也可以,所以我不知道是什么问题。

1 个答案:

答案 0 :(得分:0)

如果您正在寻找NAME命令并出现错误:

  

bash:命令名称:找不到命令

这仅表示未安装包含arp可执行文件的相关软件包net-tools,因此丢失了。默认情况下,软件包net-tools可能未安装在您的系统上,因此您需要手动安装。

该软件包还包含其他实用工具,例如arp, ifconfig, netstat, rarp, nameif and route

可能是您的shell是/bin/sh,但是net-tools软件包将其初始化放在~/.bashrc中,并期望/bin/bash

您需要获取arp初始化脚本来从非交互式bash shell运行命令。