Babel.py 文件源码

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

项目:macos-st-packages 作者: zce 项目源码 文件源码
def node_bridge(data, bin, args=[]):
    env = None
    startupinfo = None
    if os_name == 'osx':
        # GUI apps in OS X doesn't contain .bashrc/.zshrc set paths
        env = os.environ.copy()
        env['PATH'] += ':/usr/local/bin'
    elif os_name == '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('Error: Couldn\'t find "node" in "%s"' % env['PATH'])
    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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号