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

Re: [PATCH] Log everything from execWithRedirect or execWithCapture to a file.





Chris Lumens wrote:
You are changing the behavior of execWithCapture, you are now also capturing the stderr output!

Ah, whoops.  See my comment below for how to fix it.

- Chris

@@ -93,17 +115,30 @@ def execWithCapture(command, argv, stdin = 0, stderr = 2, root='/'):
     if type(stderr) == type("string"):
         stderr = open(stderr, "w")
+    runningLog = open("/tmp/program.log", "a")
+    runningLog.write("Running... %s\n" % ([command] + argv,))
+
     try:
-        pipe = subprocess.Popen([command] + argv, stdin=stdin,
+        proc = subprocess.Popen([command] + argv, stdin=stdin,
                                 stdout=subprocess.PIPE,
-                                stderr=subprocess.STDOUT,
+                                stderr=subprocess.PIPE,
                                 preexec_fn=chroot, cwd=root)
+
+        while True:
+            (outStr, errStr) = proc.communicate()
+            if outStr:
+                runningLog.write(outStr)
+                rc += outStr
+            if errStr:
+                runningLog.write(errStr)
+                rc += errStr

Remove this rc += errStr and replace it with
sys.__stdout__.write(errStr).  That at least gets us back to the
previous behavior of not capturing stderr.  What we probably should do
is write it to wherever the stderr parameter tells us to - we even open
a location for it above, but never do anything with it.


Seems like an ok solution, but it would be better to log it to the specified file, while we are making changes.

Regards,

Hans


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