def run(command, **kwargs):
    fail_hard = kwargs.pop('fail_hard', True)
    kwargs.setdefault('stdout', open('/dev/null', 'w'))
    kwargs.setdefault('stderr', open('/dev/null', 'w'))
    command = Template(command).substitute(os.environ)
    if ('TRACE' in os.environ):
        if ('cwd' in kwargs):
            print(('[cwd=%s] %s' % (kwargs['cwd'], command)))
        else:
            print(command)
    try:
        process = subprocess.Popen(command.split(' '), **kwargs)
        process.wait()
    except KeyboardInterrupt:
        process.terminate()
        raise
    if ((process.returncode != 0) and fail_hard):
        raise RunError(('Failed: ' + command))
    return process.returncode
def run(command, **kwargs):
    fail_hard = kwargs.pop('fail_hard', True)
    kwargs.setdefault('stdout', open('/dev/null', 'w'))
    kwargs.setdefault('stderr', open('/dev/null', 'w'))
    command = Template(command).substitute(os.environ)
    if ('TRACE' in os.environ):
        if ('cwd' in kwargs):
            print(('[cwd=%s] %s' % (kwargs['cwd'], command)))
        else:
            print(command)
    try:
        process = subprocess.Popen(command.split(' '), **kwargs)
        process.wait()
    except KeyboardInterrupt:
        process.terminate()
        raise
    if ((process.returncode != 0) and fail_hard):
        raise RunError(('Failed: ' + command))
    return process.returncode