当节点在环境中不可用时,如何检测是否安装了节点 [英] How to detect whether Node installed when node is not available in Environment

查看:116
本文介绍了当节点在环境中不可用时,如何检测是否安装了节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用定义要求来检查前提条件.定义要求基于外部shell脚本的结果.

I am trying to package an app that I have built for the Mac OS using the Packages software. For the app to install, there are pre-requisites which should be already installed on the system, one of which is node. I am checking for the pre requisites by Defining Requirement based on the result of an external shell script.

基本上,打包程序软件运行指定的外部脚本,如果脚本返回给定值,它将继续执行,否则将引发错误.

Basically, the packager software runs the specified external script and if the script returns a given value it proceeds else it throws an error.

我编写了以下脚本来检测是否已安装节点

I have written the following script to detect whether node is installed

#! /bin/sh
echo "Checking PreReq Node" 

node --version | grep "v" &> /dev/null 
if [ $? == 0 ]; then 
 echo "Node Installed"
 exit 0;
else 
 echo "Node not installed"
 exit 1;
fi

这在我在外壳中运行时按预期工作,但是在安装程序的上下文中运行时,节点在环境中不可用,因此会失败.如果我更改脚本以使用节点的完整路径,那么它将起作用

This works as expected when I run it in the shell, but when running within the context of the installer, node is not available in the environment so it fails. If I change the script to use the full path of node it works

#! /bin/sh
echo "Checking PreReq Node" 

/usr/local/bin/node --version | grep "v" &> /dev/null 
if [ $? == 0 ]; then 
 echo "Node Installed"
 exit 0;
else 
 echo "Node not installed"
 exit 1;
fi

但是,节点可以安装在不同系统上的不同位置.

However, node may be installed in a different location on a different system.

如何检查是否在没有实际运行节点的情况下将节点安装在系统上?

How can I check whether node is installed on a system without actually running node?

推荐答案

这可能会帮助您:

whereis node | grep ' ' -ic

这篇关于当节点在环境中不可用时,如何检测是否安装了节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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