Show
Ignore:
Timestamp:
11/19/08 17:32:54 (16 months ago)
Author:
JensDiemer
Message:

VideoTools? updates.

Location:
CodeSnippets/VideoTools
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • CodeSnippets/VideoTools

    • Property svn:ignore set to
      config.dat
  • CodeSnippets/VideoTools/shared/tools.py

    r1797 r1807  
    11# -*- coding: utf-8 -*- 
    22 
    3 import os, sys, string 
     3import os, sys, string, subprocess 
     4from pprint import pprint 
    45 
    56 
     
    7980 
    8081 
     82 
     83 
     84def subprocess2(cmd, debug=False): 
     85    """ 
     86    start a subprocess and display all output 
     87    """ 
     88    print "_"*80 
     89    print "subprocess2():" 
     90    pprint(cmd) 
     91    print " -"*40 
     92    if debug: 
     93        print "(Debug only, nothing would be started.)" 
     94        return 
     95    process = subprocess.Popen( 
     96        cmd, 
     97        stdout=subprocess.PIPE, 
     98        shell=True, 
     99    ) 
     100    output = "" 
     101    char_count = 0 
     102    while True: 
     103        char = process.stdout.read(1) 
     104        if char=="": 
     105            break 
     106 
     107        if char in ("\r", "\x08"): 
     108            continue 
     109         
     110        if char == "\n": 
     111            char_count = 0 
     112        else: 
     113            char_count += 1 
     114 
     115        output += char 
     116        sys.stdout.write(char) 
     117        if char_count>79: 
     118            sys.stdout.write("\n") 
     119            char_count = 0             
     120        sys.stdout.flush() 
     121 
     122    return process, output 
     123 
     124 
     125 
     126 
     127 
    81128if __name__ == "__main__": 
    82129    import doctest