def execute(self, cmd, wait=True): # prepend env. variables from ExcecutionContext.propagate_env_map # e.g. Given {'FOO': 1, 'BAR': 2}, we'll produce "FOO=1 BAR=2 ..." # also propagate env from command instance specific map keys = sorted(cmd.propagate_env_map.keys(), reverse=True) for k in keys: cmd.cmdStr = "%s=%s && %s" % (k, cmd.propagate_env_map[k], cmd.cmdStr) # executable='/bin/bash' is to ensure the shell is bash. bash isn't the # actual command executed, but the shell that command string runs under. self.proc = gpsubprocess.Popen(cmd.cmdStr, env=None, shell=True, executable='/bin/bash', stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) cmd.pid = self.proc.pid if wait: (rc, stdout_value, stderr_value) = self.proc.communicate2(input=self.stdin) self.completed = True cmd.set_results( CommandResult(rc, "".join(stdout_value), "".join(stderr_value), self.completed, self.halt))
def execute(self, cmd): # prepend env. variables from ExcecutionContext.propagate_env_map # e.g. Given {'FOO': 1, 'BAR': 2}, we'll produce "FOO=1 BAR=2 ..." for k, v in self.__class__.propagate_env_map.iteritems(): cmd.cmdStr = "%s=%s %s" % (k, v, cmd.cmdStr) # also propagate env from command instance specific map for k, v in cmd.propagate_env_map.iteritems(): cmd.cmdStr = "%s=%s %s" % (k, v, cmd.cmdStr) # executable='/bin/bash' is to ensure the shell is bash. bash isn't the # actual command executed, but the shell that command string runs under. self.proc = gpsubprocess.Popen(cmd.cmdStr, env=None, shell=True, executable='/bin/bash', stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) (rc, stdout_value, stderr_value) = self.proc.communicate2(input=self.stdin) self.completed = True cmd.set_results( CommandResult(rc, "".join(stdout_value), "".join(stderr_value), self.completed, self.halt))