def runExternalScript(script, allow_insecure=False, script_args=()):
    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 (OSError, 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)
Run a script (e.g. preflight/postflight) and return its exit status.
dataset/ETHPy150Open munki/munki/code/client/munkilib/utils.py/runExternalScript