diff --git a/src/python/dm/common/utility/dmSubprocess.py b/src/python/dm/common/utility/dmSubprocess.py index 7d4e5d93405f477d4bb7995dace5b1c16b024d0e..e34d15b915ddb750b6648410579a4ee13ae00eb3 100755 --- a/src/python/dm/common/utility/dmSubprocess.py +++ b/src/python/dm/common/utility/dmSubprocess.py @@ -26,17 +26,17 @@ class DmSubprocess(subprocess.Popen): # Execute command @classmethod - def executeCommand(cls, command): + def executeCommand(cls, command, cwd=None): """ Create subprocess and run it, return subprocess object. """ - p = cls.getSubprocess(command) + p = cls.getSubprocess(command, cwd) p.run() return p # Execute command, ignore errors. @classmethod - def executeCommandAndIgnoreFailure(cls, command): + def executeCommandAndIgnoreFailure(cls, command, cwd=None): """ Create subprocess, run it, igore any failures, and return subprocess object. """ - p = cls.getSubprocess(command) + p = cls.getSubprocess(command, cwd) try: p.run() except CommandFailed, ex: @@ -44,9 +44,9 @@ class DmSubprocess(subprocess.Popen): return p @classmethod - def executeCommandAndLogToStdOut(cls, command): + def executeCommandAndLogToStdOut(cls, command, cwd=None): """ Execute command, display output to stdout, maintain log file and return subprocess object. """ - p = cls.getSubprocess(command) + p = cls.getSubprocess(command, cwd) p.__commandLog() while True: @@ -76,6 +76,7 @@ class DmSubprocess(subprocess.Popen): self._stdout = None self._stderr = None self._args = args + self._cwd = cwd self.useExceptions = useExceptions self.quietMode = quietMode @@ -125,13 +126,25 @@ class DmSubprocess(subprocess.Popen): def getExitStatus(self): return self.returncode + def toDict(self): + result = { + 'command' : self._args, + 'exitStatus' : self.returncode, + 'stdErr' : self._stderr, + 'stdOut' : self._stdout, + 'workingDir' : self._cwd + } + return result + ####################################################################### # Testing. if __name__ == '__main__': p = DmSubprocess('ls -l', useExceptions=False) + print p.toDict() p.run() - print p.getStdOut() - print p.getStdErr() - print p.getExitStatus() + #print p.getStdOut() + #print p.getStdErr() + #print p.getExitStatus() + print p.toDict()