检测具有节点的系统路径上是否存在可执行文件 [英] Detect if executable exists on system path with node

查看:43
本文介绍了检测具有节点的系统路径上是否存在可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来确定使用节点的系统路径上是否有系统可执行文件?例如,如果用户在/usr/bin/python 上安装了python,并且/usr/bin $ PATH 中,该如何检测到在Node中?并反过来检测什么时候没有安装或什么不在路径上,即/usr/opt/local/mycustompath/python ?理想情况是希望他们提供npm软件包...

Is there a simple way to tell if a system executable is available on the system path using node? For example if a user has python installed at /usr/bin/python and /usr/bin is in $PATH how can I detect that in Node? And conversely detect when something isn't installed or is just not on path, i.e. /usr/opt/local/mycustompath/python? Ideally hoping their is an npm package available ...

我确定这是使用正确搜索词的Google快速搜索,但是由于在哪里和哪些是通用搜索词这一事实,我失败了.

I'm sure this is a quick google search with the right search term, but I'm failing due to the fact where and which are pretty generic search terms.

我正在为节点工具开发一些dev config,并且希望能够检测路径上是否已经存在python(或pip),如果没有,请要求用户告诉安装它或告诉我们在哪里找到它.我目前正在计划使用Windows计算机上的 where 和* nix计算机上的 which 进行此操作,但希望可以采用一种跨平台的方法来实现./p>

I'm working on some dev config for a node tool and would like to be able to detect whether python (or pip) is already available on path, and if not, ask the user to tell install it or tell us where to find it. I'm currently planning on doing this with where on windows machines and which on *nix machines, but was hoping there might be a single cross platform way of doing this.

推荐答案

软件包哈斯宾发布到npm注册表中,该注册表提供了以下功能:

Package hasbin has since been published to the npm registry, which provides this functionality:

使用 npm install hasbin

要测试Python的可用性,请按以下方式使用它(不要在可执行文件名后附加 .exe ):

To test the availability of Python, use it as follows (do not append .exe to the executable file name):

var isPyAvailable = require('hasbin').sync('python')

该软件包还有各种其他有用的方法,例如能够在几种方法中找到 first 可用二进制文件-参见其GitHub存储库.

The package has various other helpful methods, such as the ability to find the first available binary among several - see its GitHub repository.

这篇关于检测具有节点的系统路径上是否存在可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆