]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/lilylib.py
Merge branch 'master' of git://git.savannah.gnu.org/lilypond.git
[lilypond.git] / python / lilylib.py
index dac53c16cf4dd5d83c2111e4ba49e28701f410b0..c3eb98bc6fda38f815b5bc9ebf8d41f91dd46a85 100644 (file)
@@ -23,6 +23,7 @@ import re
 import shutil
 import sys
 import optparse
+import time
 
 ################################################################
 # Users of python modules should include this snippet
@@ -118,6 +119,7 @@ def subprocess_system (cmd,
                        ignore_error=False,
                        progress_p=True,
                        be_verbose=False,
+                       redirect_output=False,
                        log_file=None):
     import subprocess
 
@@ -125,31 +127,46 @@ def subprocess_system (cmd,
     name = command_name (cmd)
     error_log_file = ''
 
-    if be_verbose:
-       show_progress = 1
-       progress (_ ("Invoking `%s\'") % cmd)
+    if redirect_output:
+        progress (_ ("Processing %s.ly") % log_file)
     else:
-       progress ( _("Running %s...") % name)
-
+        if be_verbose:
+            show_progress = 1
+            progress (_ ("Invoking `%s\'") % cmd)
+        else:
+            progress ( _("Running %s...") % name)
 
     stdout_setting = None
+    stderr_setting = None
     if not show_progress:
-       stdout_setting = subprocess.PIPE
+        stdout_setting = subprocess.PIPE
+
+    if redirect_output:
+        stdout_filename = ' '.join([log_file, '.log'])
+        stderr_filename = ' '.join([log_file, '.err.log'])
+        stdout_setting = open(stdout_filename, 'w')
+        stderr_setting = open(stderr_filename, 'w')
 
     proc = subprocess.Popen (cmd,
                              shell=True,
                              universal_newlines=True,
                              stdout=stdout_setting,
-                             stderr=stdout_setting)
+                             stderr=stderr_setting)
 
     log = ''
 
-    if show_progress:
-       retval = proc.wait()
+    if redirect_output:
+        while proc.poll()==None:
+            time.sleep(1)
+        retval = proc.returncode
+        stdout_setting.close()
+        stderr_setting.close()
     else:
-       log = proc.communicate ()
-       retval = proc.returncode
-
+        if show_progress:
+            retval = proc.wait()
+        else:
+            log = proc.communicate ()
+            retval = proc.returncode
 
     if retval:
         print >>sys.stderr, 'command failed:', cmd