Changeset 1807 for CodeSnippets/VideoTools/shared/tools.py
- Timestamp:
- 11/19/08 17:32:54 (16 months ago)
- Location:
- CodeSnippets/VideoTools
- Files:
-
- 2 modified
-
. (modified) (1 prop)
-
shared/tools.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CodeSnippets/VideoTools
-
Property
svn:ignore set
to
config.dat
-
Property
svn:ignore set
to
-
CodeSnippets/VideoTools/shared/tools.py
r1797 r1807 1 1 # -*- coding: utf-8 -*- 2 2 3 import os, sys, string 3 import os, sys, string, subprocess 4 from pprint import pprint 4 5 5 6 … … 79 80 80 81 82 83 84 def 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 81 128 if __name__ == "__main__": 82 129 import doctest