I have the problem that I need to interact with a CD/DVD burning program called gear. I do this by running it in a pseudo terminal.
I also need to log what I'm doing, so I copy all output I get from gear to a logfile. The problem is that gear uses terminal control commands to create a nice commandline interface. I can filter out all non printable characters to get something I can put in my logfile, but this leaves a lot of the terminal control commands. My problem is that the control sequences are variable in length, and themselves printable text. they probably vary depending on the $TERM setting too. Does anyone have code that can parse this, so I can get rid of the ugly control sequences? Any suggestions on how to do this with regular expressions is welcome too, with my limited knowledge I don't know how to do it. Finding the beginning is kind of easy, as it always starts with <unprinteable control character>[, but the length varies after that. My output now looks like this: 2005-07-28 14:27:58 Message : [76C^M Scanning busses for recorder devices...please wait... 2005-07-28 14:27:59 Message : [K[77C^M Driver found: Linux Scsi Generic v3 Driver. 2005-07-28 14:27:59 Message : [76C^M PLEXTOR DVDR PX-716A revision 1.07 found on /dev/sg1 2005-07-28 14:27:59 Message : 2005-07-28 14:27:59 Message : [76C^M [23;54H[25DPLEXTOR DVDR PX-716A [11;78H^M Recorder PLEXTOR DVDR PX-716A used. 2005-07-28 14:27:59 Message : [9B[K[79C[6DReady^M[K[79C[18DInitializing tape^M[K[79C [25DInitializing tape driver[12;78H^M Selected tape interface: Standard SCSI driver 2005-07-28 14:27:59 Message : [76C^M Scanning bus for tape units...please wait...^M [K[77C^M Driver found: Linux Scsi Generic v3 Driver. 2005-07-28 14:27:59 Message : [76C^M HP[7CC5683A[11Crevision C908 found on /dev/sg0 I would like: 2005-07-28 14:27:58 Message : Scanning busses for recorder devices...please wait... 2005-07-28 14:27:59 Message : Driver found: Linux Scsi Generic v3 Driver. 2005-07-28 14:27:59 Message : PLEXTOR DVDR PX-716A revision 1.07 found on /dev/sg1 2005-07-28 14:27:59 Message : 2005-07-28 14:27:59 Message : PLEXTOR DVDR PX-716A Recorder PLEXTOR DVDR PX-716A used. 2005-07-28 14:27:59 Message : Ready Initializing tape Initializing tape driver Selected tape interface: Standard SCSI driver 2005-07-28 14:27:59 Message : Scanning bus for tape units...please wait... Driver found: Linux Scsi Generic v3 Driver. 2005-07-28 14:27:59 Message : HP 5683A revision 08 found on /dev/sg0 Thank you. -- http://mail.python.org/mailman/listinfo/python-list