可靠地确定用于运行node.js脚本的shell(cmd,bash或等)

时间:2017-04-01 19:41:04

标签: node.js bash shell

正如标题所述,我想确定使用哪个shell(import requests import sys import os import json import io from objbrowser import browse class RadioStations(): user_agent = {'User-agent': 'User-Agent: XBMC Addon Radio'} data = [] no_data = True url = "http://radio.de/info/menu/broadcastsofcategory?category=_top" try: response = requests.get(url, headers = user_agent) data = response.json() no_data = False print("Data found") except requests.HTTPError, e: print("HTTP error %s", e.code) no_data = False except requests.ConnectionError, e: data.append({'name': 'no station data'}) no_data = True print("Connection error %s", e) print("Getting StreamUrls and creating files") for item in data: id2 = str(item['id']) url = "http://radio.de/info/broadcast/getbroadcastembedded?broadcast=" + id2 response = requests.get(url, headers = user_agent) station_data = response.json() with open("{}.pls".format(station_data['name']).encode('utf-8'), "wb") as file: txt = "[playlist]\nnumberofentries=1\nFile1={}\nTitle1={}".format(station_data['streamURL'],station_data['name']) file.write(txt) if "errorCode" in station_data.keys(): print("no such entry") print("Finished") cmd或者等)来运行node.js脚本(从脚本中)。

虽然使用bash模块检测操作系统可以提供一些线索,但是某些实例是不够的,例如我在os bash上通过终端执行例如GitBashCygwin

win32对象上是否有某个属性包含此信息?

*编辑:虽然process是一个选项,但它并不总是填充,并且在使用某些终端时可能process.env.SHELL

1 个答案:

答案 0 :(得分:2)

您可以使用process.env.SHELL属性来获取该功能,如官方文档中所示

process.env属性返回包含用户环境的对象。此对象的示例如下所示:

{
  TERM: 'xterm-256color',
  SHELL: '/usr/local/bin/bash',
  USER: 'maciej',
  PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
  PWD: '/Users/maciej',
  EDITOR: 'vim',
  SHLVL: '1',
  HOME: '/Users/maciej',
  LOGNAME: 'maciej',
  _: '/usr/local/bin/node'
}