diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-13 05:43:39 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-13 05:43:39 +0000 |
commit | 19ae07d0d443ff8b777f46bcbe97119483356bfd (patch) | |
tree | dae169167c23ba7c61814101995de21d6abac2e8 /displayconfig/execwithcapture.py | |
download | tde-guidance-19ae07d0d443ff8b777f46bcbe97119483356bfd.tar.gz tde-guidance-19ae07d0d443ff8b777f46bcbe97119483356bfd.zip |
Added KDE3 version of KDE Guidance utilities
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kde-guidance@1102646 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'displayconfig/execwithcapture.py')
-rw-r--r-- | displayconfig/execwithcapture.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/displayconfig/execwithcapture.py b/displayconfig/execwithcapture.py new file mode 100644 index 0000000..10c8e23 --- /dev/null +++ b/displayconfig/execwithcapture.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +import os +import select + +############################################################################ +def ExecWithCapture(command, argv, searchPath = 0, root = '/', stdin = 0, + catchfd = 1, closefd = -1): + + if not os.access(root + command, os.X_OK) and not searchPath: + raise RuntimeError, command + " can not be run" + + (read, write) = os.pipe() + childpid = os.fork() + if (not childpid): + if (root and root != '/'): os.chroot(root) + os.dup2(write, catchfd) + os.close(write) + os.close(read) + + if closefd != -1: + os.close(closefd) + if stdin: + os.dup2(stdin, 0) + os.close(stdin) + 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) + + try: + os.waitpid(childpid, 0) + except OSError, (errno, msg): + print __name__, "waitpid:", msg + + return rc |