简体   繁体   中英

pexpect output in different window

Now I am working in a project where the testscript has to connect many (3-10) remote computers (SSH and do some stuff). I started to use the pexpect and it is simple as a button. It works fine.

I want to see the communication during test. I know it is possible to redirect the log to the screen. But in this case the logs (from different computer) are mixed. What I would like is to open new terminal window (or consol or whatever) for every new spawn object. In this case I could see all communication in different windows. Additionally I would like to keep the possibility of spawn.interact() in every window. I feel that it is possible somehow but I don't know how. I think some file pointer (or pipe) should pass to the new window somehow(?) (SecureCRT knows sometihng like this, it has tabbed consol windows and can access them separately, but it is a commercial product)

Or let me make the problem more simple. If I do this, I can open a new shell in a new window:

p=Popen(["cygstart", "bash"])

How can I read and write into this shell from my script (parent) to see it in this new window?

I would really appreciate it, if one of you could point me in the right direction.

It is enough if you tell me what to read or find for (on Google) because I did not find anybody such kind of problem. The environment is cygwin.

Thanks in advance

br:drv

Have you tried using the logfile parameter?

child = pexpect.spawn('some_command')
mylog = open('/tmp/mylog','w')
child.logfile = mylog

This will automatically log all communication to the file, including commands you enter after calling spawn.interact()

More info available on the website: http://pexpect.sourceforge.net/pexpect.html Search for 'logfile' to find the relevant documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM