import os
import subprocess

__all__ = ['check_output', 'popen', 'PIPE']

# 模块级单例，导入时只创建一次
if os.name == "nt":
    _si = subprocess.STARTUPINFO()
    _si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    _si.wShowWindow = subprocess.SW_HIDE
else:
    _si = None

PIPE = subprocess.PIPE

def check_output(cmd, **kw):
    if os.name == "nt":
        kw.setdefault('startupinfo', _si)
    return subprocess.check_output(cmd, **kw)

def popen(*args, **kw):
    if os.name == "nt":
        kw.setdefault('startupinfo', _si)
    return subprocess.Popen(*args, **kw)