code: def run_program(self, command, working_directory=os.getcwd(),
                      environment=None, cleanup_files=True,
                      native_spec="-l cputype=intel"):
          
          try:
              s = drmaa.Session()
              s.initialize()
              jt = s.createJobTemplate()
              jt.remoteCommand = os.path.dirname(
                  os.path.abspath(__file__)) + '/run_program.sh'
              jt.args = [command]
  
              if environment is not None:
                  jt.jobEnvironment = environment
  
              jt.workingDirectory = working_directory
              jt.nativeSpecification = native_spec
              output_filename = os.path.join(working_directory, 'output.txt')
              jt.outputPath = ':' + output_filename
              jt.joinFiles = True
  
              jobid = s.runJob(jt)
  
              s.wait(jobid, drmaa.Session.TIMEOUT_WAIT_FOREVER)
  
              with open(output_filename, 'r') as output:
                  stdout = output.read()
  
              # Clean up
              if cleanup_files:
                  os.remove(output_filename)
  
          finally:
              try:
                  s.control(drmaa.JOB_IDS_SESSION_ALL,
                            drmaa.JobControlAction.TERMINATE)
                  s.synchronize([drmaa.JOB_IDS_SESSION_ALL], dispose=True)
                  s.exit()
              except(drmaa.errors.NoActiveSessionException):
                  pass
  
          return stdout
docs: Run a program through the grid, capturing the standard output.