运行 NodeJS 脚本作为守护进程时无法获取 iwgetid

Not able to get iwgetid when running NodeJS Script as daemon

我正在构建一个 Raspberry PI3 网络服务器,其中一个页面应该显示我的 raspberry PI 当前连接到的无线网络的 SSID。为此,我正在使用(在 NodeJS 中):

require("child_process").exec('iwgetid',callback....)

如果我在 SSH 中执行脚本,它会 运行s 符合预期。但是,如果我 运行 这是服务,我会在 /var/log/syslog 中得到以下输出:

Jul 30 16:21:10 raspberrypi2 index.js[11406]: Child process exited with error code ErrorCommand failed: iwgetid Jul 30 16:21:10 raspberrypi2 index.js[11406]: /bin/sh: 1: iwgetid: not found

当您运行将其作为服务时,路径环境变量可能会有所不同。您的第一步可能是尝试使用绝对路径。

require("child_process").exec('/sbin/iwgetid',callback....)