since I do not have access to xterm, here is the interactive session for spawning bash(another session if you will), sending ls command to it, and retrieving the results. things to note are: 1. after spawning expect for the prompt, timeout, and eof #which ever happens first 2. return value is the action that matched 3. if prompt matched, the 'before' has the results 4. even the command 'ls' with '\r\n' will be in the results. ------------actual session-------------------------- [EMAIL PROTECTED]:/c/Edwin/Projects/expect $ python Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import pexpect >>> c = pexpect.spawn('/bin/bash') >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 >>> c.before '[EMAIL PROTECTED]:/c/Edwin/Projects/expect\r\n' >>> c.after '$ ' >>> c.sendline('ls') 3 >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 >>> c.before '[EMAIL PROTECTED]:/c/Edwin/Projects/expect\r\n' >>> c.after '$ ' >>> >>> exit() [EMAIL PROTECTED]:/c/Edwin/Projects/expect $ ---------------------------------------------------------------
good luck.... Edwin -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Tenney Sent: Friday, August 08, 2008 4:25 PM To: python-list@python.org Subject: sending to an xterm Howdy, I want to open an xterm, send it a command and have it execute it. I thought pexpect would do this, but I've been unsuccessful. term = pexpect.spawn('xterm') starts an xterm, but term.sendline('ls') doesn't seem to do anything. Suggestions? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list