diff options
author | Erik Troan <ewt@redhat.com> | 1999-08-23 23:32:19 +0000 |
---|---|---|
committer | Erik Troan <ewt@redhat.com> | 1999-08-23 23:32:19 +0000 |
commit | 3de2ba0b65eab40e835f83defa3ba0f0097851ad (patch) | |
tree | 01e6e4445cd2d4c2d05ce5234fb7167cbbf1b36a /iutil.py | |
parent | 75b6f43dad6759edbd98bc3700eef0219820a0db (diff) | |
download | anaconda-3de2ba0b65eab40e835f83defa3ba0f0097851ad.tar.gz anaconda-3de2ba0b65eab40e835f83defa3ba0f0097851ad.tar.xz anaconda-3de2ba0b65eab40e835f83defa3ba0f0097851ad.zip |
added execWithCapture
Diffstat (limited to 'iutil.py')
-rw-r--r-- | iutil.py | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -1,5 +1,5 @@ -import types, os, sys, isys +import types, os, sys, isys, select def getfd(filespec, readOnly = 0): if type(filespec) == types.IntType: @@ -40,3 +40,34 @@ def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2, (pid, status) = os.waitpid(childpid, 0) return status + +def execWithCapture(command, argv, searchPath = 0, root = '/'): + + (read, write) = os.pipe() + + childpid = os.fork() + if (not childpid): + if (root != '/'): isys.chroot (root) + os.dup2(write, 1) + + if (searchPath): + os.execvp(command, argv) + else: + os.execv(command, argv) + + sys.exit(1) + + os.close(write) + + rc = "" + s = "1" + while (s): + select.select([read], [], []) + s = os.read(read, 1000) + rc = rc + s + + os.close(read) + + os.waitpid(childpid, 0) + + return rc |