Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

sending to an xterm

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


ktenney at gmail

Aug 8, 2008, 1:25 PM

Post #1 of 7 (548 views)
Permalink
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


emile at fenx

Aug 8, 2008, 1:55 PM

Post #2 of 7 (541 views)
Permalink
Re: sending to an xterm [In reply to]

Kent Tenney wrote:
> 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
>

expect or http://www.noah.org/wiki/Pexpect


Emile

--
http://mail.python.org/mailman/listinfo/python-list


code at pizzashack

Aug 8, 2008, 1:58 PM

Post #3 of 7 (541 views)
Permalink
Re: sending to an xterm [In reply to]

On Fri, Aug 08, 2008 at 08:25:19PM +0000, Kent Tenney wrote:
> Howdy,
>
> I want to open an xterm, send it a command and have it execute it.

You can't do that. xterm doesn't execute shell commands passed on
stdin... It can, however, execute one passed on the command line.

Instead of just running xterm, you can run "xterm -e 'cmd foo bar'"
where cmd is the program to run and foo and bar are its arguments.
The problem is that as soon as the program exits, xterm will exit
also.

--
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D


ktenney at gmail

Aug 8, 2008, 2:13 PM

Post #4 of 7 (542 views)
Permalink
Re: sending to an xterm [In reply to]

Derek Martin <code <at> pizzashack.org> writes:

>
> On Fri, Aug 08, 2008 at 08:25:19PM +0000, Kent Tenney wrote:
> > Howdy,
> >
> > I want to open an xterm, send it a command and have it execute it.
>
> You can't do that. xterm doesn't execute shell commands passed on
> stdin... It can, however, execute one passed on the command line.
>
> Instead of just running xterm, you can run "xterm -e 'cmd foo bar'"
> where cmd is the program to run and foo and bar are its arguments.
> The problem is that as soon as the program exits, xterm will exit
> also.
>

OK, I see that.

(getting off topic)

any chance of keeping the xterm open after running the command?

Thanks,
Kent



--
http://mail.python.org/mailman/listinfo/python-list


ktenney at gmail

Aug 8, 2008, 2:21 PM

Post #5 of 7 (540 views)
Permalink
Re: sending to an xterm [In reply to]

Derek Martin <code <at> pizzashack.org> writes:

>
> On Fri, Aug 08, 2008 at 08:25:19PM +0000, Kent Tenney wrote:
> > Howdy,
> >
> > I want to open an xterm, send it a command and have it execute it.
>
> You can't do that. xterm doesn't execute shell commands passed on
> stdin... It can, however, execute one passed on the command line.
>
> Instead of just running xterm, you can run "xterm -e 'cmd foo bar'"
> where cmd is the program to run and foo and bar are its arguments.
> The problem is that as soon as the program exits, xterm will exit
> also.
>

Sorry to reply before getting googly

This appears to be a solution;

xterm -e "ls; bash"

http://www.linuxforums.org/forum/misc/115239-getting-prompt-after-xterm-e-command.html


--
http://mail.python.org/mailman/listinfo/python-list


Edwin.Madari at VerizonWireless

Aug 8, 2008, 2:47 PM

Post #6 of 7 (535 views)
Permalink
RE: sending to an xterm [In reply to]

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--------------------------
madared[at]WNJ10002LBITAZV:/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
'\x1b[?1034hmadared[at]WNJ10002LBITAZV:/c/Edwin/Projects/expect\r\n'
>>> c.after
'$ '
>>> c.sendline('ls')
3
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before
'ls\r\nautoexpect.exp\tscript.exp\r\nmadared[at]WNJ10002LBITAZV:/c/Edwin/Projects/expect\r\n'
>>> c.after
'$ '
>>>
>>> exit()
madared[at]WNJ10002LBITAZV:/c/Edwin/Projects/expect
$
---------------------------------------------------------------

good luck....
Edwin
-----Original Message-----
From: python-list-bounces+edwin.madari=verizonwireless.com[at]python.org
[mailto:python-list-bounces+edwin.madari=verizonwireless.com[at]python.org]
On Behalf Of Kent Tenney
Sent: Friday, August 08, 2008 4:25 PM
To: python-list[at]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


healey.rich at gmail

Aug 8, 2008, 10:17 PM

Post #7 of 7 (529 views)
Permalink
Re: sending to an xterm [In reply to]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kent Tenney wrote:
> Derek Martin <code <at> pizzashack.org> writes:
>
>> On Fri, Aug 08, 2008 at 08:25:19PM +0000, Kent Tenney wrote:
>>> Howdy,
>>>
>>> I want to open an xterm, send it a command and have it execute it.
>> You can't do that. xterm doesn't execute shell commands passed on
>> stdin... It can, however, execute one passed on the command line.
>>
>> Instead of just running xterm, you can run "xterm -e 'cmd foo bar'"
>> where cmd is the program to run and foo and bar are its arguments.
>> The problem is that as soon as the program exits, xterm will exit
>> also.
>>
>
> OK, I see that.
>
> (getting off topic)
>
> any chance of keeping the xterm open after running the command?
>
> Thanks,
> Kent
>
xterm -hold -e "whatever"

>
>
> --
> http://mail.python.org/mailman/listinfo/python-list


- --
Rich Healey - healey.rich[at]gmail.com
Developer / Systems Admin - OpenPGP: 0x8C8147807
MSN: bitchohealey[at]hotmail.com AIM: richohealey33
irc.psych0tik.net -> #hbh #admins richohealey
irc.freenode.org -> #hbh #debian PythonNinja
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkidKIAACgkQLeTfO4yBSAclUwCg3uuvxxWHgZ/vqenrmaNIV/iE
ceQAn3e8oC6t0rTLtVhpeisujnqq8jlh
=4s8n
-----END PGP SIGNATURE-----
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.