#!/usr/bin/env python import base64 import os import stat import subprocess import sys import tempfile import traceback assert sys.argv[0] == '-c' base64_code = sys.argv[1] code_args = sys.argv[2:] retval = 255 try: tempf = tempfile.NamedTemporaryFile(prefix='automate_program_', delete=False) tempf.write(base64.standard_b64decode(base64_code)) tempf.flush() os.fchmod(tempf.fileno(), stat.S_IRUSR | stat.S_IXUSR | stat.S_IROTH | stat.S_IXOTH) tempf.close() # Close the tempfile so that shebang execution works. process = subprocess.Popen([tempf.name] + code_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = process.communicate() print stdout print>>sys.stderr, stderr retval = process.returncode assert retval is not None except EnvironmentError, e: frame_limit = 30 print ('BOOTSTRAP: could not properly bootstrap program literal, ' 'stack trace (truncated to {0} frames) follows' .format(frame_limit)) traceback.print_exc(limit=frame_limit, file=sys.stdout) retval = 255 finally: # Clean up the tempfile in case anything went wrong if tempf is not None: os.unlink(tempf.name) sys.exit(retval)

AltStyle によって変換されたページ (->オリジナル) /