节点查看是否已安装程序 [英] Node see if Program is installed
问题描述
您好,我正在制作需要以下内容的节点应用程序:ffmpeg, node-acoutstid with fpcalc and eye3D
.
现在是我的问题,如何查看客户端计算机上是否安装了这些程序".
Hello im making a node app that requires: ffmpeg, node-acoutstid with fpcalc and eye3D
.
Now is my question how i can see if those 'programs' are installed on the clients machine.
什么是最好的检查方法?
whats the best way to check this ?
推荐答案
掏空"进行本机检测
在macOS/Linux/bash中,我们通常会使用type -p
或command -v
(如果您做错了,请使用which
).
"shell out" for native detection
In macOS / Linux / bash we'd typically use type -p
or command -v
(or which
if you're doing it wrong).
在Windows中,您可以像where node.exe
一样使用where
.
In windows there's where
that you can use like where node.exe
.
require('child_process').exec('type -p mything', function (err, stdout) {
console.log(stdout);
});
如果您不想跨平台兼容并且不必担心清理用户输入,那么这种天真的方法就可以工作.
This naive approach can work if you're not trying to be cross-platform compatible and if you don't have to worry about sanitizing user input.
在npm上有一个软件包 command-exists .我偷看了一下代码,看起来它可能是最简单的跨平台检测,可以覆盖小尺寸的边缘情况:
On npm there's a package command-exists. I peeked at the code and it looks like it's probably the simplest cross-platform detection that covers edge cases at a small size:
https://github.com/mathisonian/command-exists/blob/master/lib/command-exists.js
var commandExists = require('command-exists');
// invoked without a callback, it returns a promise
commandExists('ls').then(function (command) {
// proceed
}).catch(function () {
// command doesn't exist
});
这篇关于节点查看是否已安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!