def runExternalScript(script, allow_insecure=False, script_args=()):
    """Run a script (e.g. preflight/postflight) and return its exit status.

    Args:
      script: string path to the script to execute.
      allow_insecure: bool skip the permissions check of executable.
      args: args to pass to the script.
    Returns:
      Tuple. (integer exit status from script, str stdout, str stderr).
    Raises:
      ScriptNotFoundError: the script was not found at the given path.
      RunExternalScriptError: there was an error running the script.
    """
    if not os.path.exists(script):
        raise ScriptNotFoundError('script does not exist: %s' % script)

    if not allow_insecure:
        try:
            verifyFileOnlyWritableByMunkiAndRoot(script)
        except VerifyFilePermissionsError, err:
            msg = ('Skipping execution due to failed file permissions '
                   'verification: %s\n%s' % (script, str(err)))
            raise RunExternalScriptError(msg)

    if os.access(script, os.X_OK):
        cmd = [script]
        if script_args:
            cmd.extend(script_args)
        proc = None
        try:
            proc = subprocess.Popen(cmd, shell=False,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
        except (__HOLE__, IOError), err:
            raise RunExternalScriptError(
                'Error %s when attempting to run %s' % (unicode(err), script))
        if proc:
            (stdout, stderr) = proc.communicate()
            return proc.returncode, stdout.decode('UTF-8', 'replace'), \
                                    stderr.decode('UTF-8', 'replace')
    else:
        raise RunExternalScriptError('%s not executable' % script)
dataset/ETHPy150Open munki/munki/code/client/munkilib/utils.py/runExternalScript