[rhel5-branch] Make execWithRedirect() append to the files. (#702024)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Otherwise stdout output is lost if we pass the same filename for stdout
and stderr.
---
 iutil.py |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/iutil.py b/iutil.py
index c482b18..9a53b16 100644
--- a/iutil.py
+++ b/iutil.py
@@ -36,15 +36,24 @@ def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2,
         if not searchPath and not os.access (command, os.X_OK):
             raise RuntimeError, command + " can not be run"
 
+    def try_truncate(f):
+        try:
+            f.truncate(0)
+        except IOError, e:
+            # will fail for e.g. for /dev/tty5
+            pass
+
     if type(stdin) == type("string"):
         if os.access(stdin, os.R_OK):
             stdin = open(stdin)
         else:
             stdin = 0
     if type(stdout) == type("string"):
-        stdout = open(stdout, "w")
+        stdout = open(stdout, "a")
+        try_truncate(stdout)
     if type(stderr) == type("string"):
-        stderr = open(stderr, "w")
+        stderr = open(stderr, "a")
+        try_truncate(stderr)
 
     try:
         proc = subprocess.Popen([command] + argv, stdin=stdin, stdout=stdout,
-- 
1.7.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux