Re: Output of pexpect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lie Ryan

    Re: Output of pexpect

    On Tue, 30 Sep 2008 20:48:12 -0700, Anh Khuong wrote:

    I am using pexpect and I want to send output of pexpet to both stdout
    and log file concurrently. Anybody know a solution for it please let me
    know.
    One way is to create a file-like object that forked the output to stdout
    and the logfile.

    class forkwriter(obje ct):
    def __init__(self, filename):
    self.file = open(filename, 'w')
    def write(self, s):
    sys.stdout.writ e(s)
    self.file.write (s)

    I've never used pexpect myself though, but if pexpect write things to the
    to the stdout, then you can redirect stdout

    import sys
    sys.stdout = forkwriter('myl og.log')

    (note: the forkwriter class would have to be modified a bit to use the
    "background " sys.__stdout__ instead of sys.stdout)

Working...