node_bridge.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Sublime-svgo 作者: 1000ch 项目源码 文件源码
def node_bridge(data, bin, args=[]):
  env = None
  startupinfo = None

  if IS_MACOS:
    env = os.environ.copy()
    env['PATH'] += ':/usr/local/bin'

  if IS_WINDOWS:
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

  try:
    p = subprocess.Popen(['node', bin] + args,
      stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
      env=env, startupinfo=startupinfo)
  except OSError:
    raise Exception('Couldn\'t find Node.js. Make sure it\'s in your $PATH by running `node -v` in your command-line.')

  stdout, stderr = p.communicate(input=data.encode('utf-8'))
  stdout = stdout.decode('utf-8')
  stderr = stderr.decode('utf-8')

  if stderr:
    raise Exception('Error: %s' % stderr)
  else:
    return stdout
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号