From: Robin L. P. <rlp...@di...> - 2008-12-06 04:52:53
|
I'm trying to send arrow keys to a curses app of mine. Rather than distributing that app, here's an example using "mutt", which is fairly common: - ----------- #!/usr/bin/perl use warnings; use strict; use Expect; my $timeout = 20; $Expect::Log_Stdout = 1; #$Expect::Debug = 1; #$Expect::Exp_Internal = 1; my $exp; $exp = new Expect (); $exp->raw_pty(1); $exp = Expect->spawn("/usr/bin/mutt") or die "Cannot spawn client: $!\n"; $exp->expect($timeout, "Mutt:" ); $exp->send("\e[B"); $exp->send("\e[B"); $exp->send("\e[B"); $exp->send("\e[B"); $exp->send("\e[B"); $exp->send("\e[B"); $exp->send("\e[B"); sleep 1; $exp->send("\cl"); sleep 20; print "Done sending.\n"; - ----------- To see it work, mutt will have to be pointing at a mail file/folder that has a few things in it so you can see it trying to scroll down; "-f [file]" may be useful there. \e[B is most definitely what my keyboard is sending, but the expect script causes exactly nothing to happen on the mutt screen. Curses' getch() says that the character's value is "258", but sending chr(258) doesn't help either. Suggestions? -Robin -- They say: "The first AIs will be built by the military as weapons." And I'm thinking: "Does it even occur to you to try for something other than the default outcome?" -- http://shorl.com/tydruhedufogre http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/ |
From: Robin L. P. <rlp...@di...> - 2008-12-11 18:55:52
|
On Fri, Dec 05, 2008 at 08:52:46PM -0800, Robin Lee Powell wrote: > > I'm trying to send arrow keys to a curses app of mine. Rather > than distributing that app, here's an example using "mutt", which > is fairly common: No-one knows how to send arrows to curses apps in Expect? -Robin -- They say: "The first AIs will be built by the military as weapons." And I'm thinking: "Does it even occur to you to try for something other than the default outcome?" -- http://shorl.com/tydruhedufogre http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/ |
From: Bryan B. <br...@bu...> - 2008-12-12 09:06:50
|
> On Fri, Dec 05, 2008 at 08:52:46PM -0800, Robin Lee Powell wrote: >> >> I'm trying to send arrow keys to a curses app of mine. Rather >> than distributing that app, here's an example using "mutt", which >> is fairly common: > > No-one knows how to send arrows to curses apps in Expect? > > -Robin > By my reckoning, you have your string incorrect. The following should be arrow keys: $up = "\c[[A"; $down = "\c[[B"; $left = "\c[[D"; $right = "\c[[C"; and not "\e[[B"; Hope that helps. Bryan Bueter http://sourceforge.net/project/rover |
From: John S. <joh...@ch...> - 2008-12-12 13:32:49
|
I have several PERL scripts which I use to connect Cisco routers via telnet but I ran into trouble developing one that connects via SSH. After doing extensive research, I was lead to Expect.pm and this forum. As I have never done anything with Expect, I was hoping that someone could possibly give me an example script to connect to a Cisco router via SSH so I could have a solid starting point? Thank you if you can. john |
From: Robin L. P. <rlp...@di...> - 2008-12-12 12:16:09
|
On Thu, Dec 11, 2008 at 03:53:11PM -0500, Bryan Bueter wrote: > > On Fri, Dec 05, 2008 at 08:52:46PM -0800, Robin Lee Powell wrote: > >> > >> I'm trying to send arrow keys to a curses app of mine. Rather > >> than distributing that app, here's an example using "mutt", which > >> is fairly common: > > > > No-one knows how to send arrows to curses apps in Expect? > > > > -Robin > > > > By my reckoning, you have your string incorrect. The following should be > arrow keys: > > $up = "\c[[A"; > $down = "\c[[B"; > $left = "\c[[D"; > $right = "\c[[C"; > > and not "\e[[B"; I wasn't sending \e[[B, I was sending \e[B. \e == \c[ (that is, ESC is the same as ^[; I actually use ctrl-[ at the keyboard most of the time to send ESC). I did explicitely try $exp->send("\c[[B");, though. No change (i.e., nothing happens). -Robin -- They say: "The first AIs will be built by the military as weapons." And I'm thinking: "Does it even occur to you to try for something other than the default outcome?" -- http://shorl.com/tydruhedufogre http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/ |
From: Bryan B. <br...@bu...> - 2008-12-12 13:46:58
|
> On Thu, Dec 11, 2008 at 03:53:11PM -0500, Bryan Bueter wrote: >> > On Fri, Dec 05, 2008 at 08:52:46PM -0800, Robin Lee Powell wrote: >> >> >> >> I'm trying to send arrow keys to a curses app of mine. Rather >> >> than distributing that app, here's an example using "mutt", which >> >> is fairly common: >> > >> > No-one knows how to send arrows to curses apps in Expect? >> > >> > -Robin >> > >> >> By my reckoning, you have your string incorrect. The following should >> be >> arrow keys: >> >> $up = "\c[[A"; >> $down = "\c[[B"; >> $left = "\c[[D"; >> $right = "\c[[C"; >> >> and not "\e[[B"; > > I wasn't sending \e[[B, I was sending \e[B. > > \e == \c[ (that is, ESC is the same as ^[; I actually use ctrl-[ at > the keyboard most of the time to send ESC). > > I did explicitely try $exp->send("\c[[B");, though. No change > (i.e., nothing happens). > > -Robin > Yes, i see that now. When i type: cat > test.txt Then hit the arrow key it gives me control+[[B, thats why i suggested that and not escape+[B. And i pulled \e[[B from my memory of your previous e-mail, not from the e-mail itself. So my apologies. As for running mutt through expect, it seems to ignore everything i send, even if I just try and open it up quit. So I dont think there is actually anything wrong with what your sending, just how its being interpreted by mutt. Bryan Bueter http://sourceforge.net/projects/rover |
From: Robin L. P. <rlp...@di...> - 2008-12-12 14:20:59
|
On Fri, Dec 12, 2008 at 08:46:45AM -0500, Bryan Bueter wrote: > As for running mutt through expect, it seems to ignore everything > i send, even if I just try and open it up quit. So I dont think > there is actually anything wrong with what your sending, just how > its being interpreted by mutt. Mutt works just fine seding "j" keys; you have to expect something to see the updates though. How about this; I've got an example that uses "less", which pretty much everybody should have. Run: seq 1 500 >/tmp/crap Then try this code: - ---------------------- #!/usr/bin/perl use warnings; use strict; use Expect; my $timeout = 5; $Expect::Log_Stdout = 1; #$Expect::Debug = 1; #$Expect::Exp_Internal = 1; my $exp; $exp = new Expect (); $exp->raw_pty(1); $exp = Expect->spawn("/usr/bin/less", "/tmp/crap") or die "Cannot spawn client: $!\n"; $exp->log_file( "/tmp/exp.out", "w" ); $exp->expect($timeout, "crap" ); print "done expect.\n"; $exp->send("\c[[B"); $exp->send("\c[[B"); $exp->send("\e[B"); $exp->expect($timeout, "26" ); sleep 5; print "done arrows.\n"; $exp->send("j"); $exp->send("j"); $exp->send("j"); sleep 5; $exp->expect($timeout, "26" ); $exp->send("q"); sleep 5; $exp->expect($timeout, "crap" ); print "Done sending.\n"; - ---------------------- As you can see, the arrow keys do nothing, but the j keys work just fine. -Robin -- They say: "The first AIs will be built by the military as weapons." And I'm thinking: "Does it even occur to you to try for something other than the default outcome?" -- http://shorl.com/tydruhedufogre http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/ |
From: Bryan B. <br...@bu...> - 2008-12-12 16:18:08
|
> On Fri, Dec 12, 2008 at 08:46:45AM -0500, Bryan Bueter wrote: >> As for running mutt through expect, it seems to ignore everything >> i send, even if I just try and open it up quit. So I dont think >> there is actually anything wrong with what your sending, just how >> its being interpreted by mutt. > > Mutt works just fine seding "j" keys; you have to expect something > to see the updates though. > > How about this; I've got an example that uses "less", which pretty > much everybody should have. Run: > > seq 1 500 >/tmp/crap > > Then try this code: > > - ---------------------- > > #!/usr/bin/perl > > use warnings; > use strict; > > use Expect; > > my $timeout = 5; > > $Expect::Log_Stdout = 1; > #$Expect::Debug = 1; > #$Expect::Exp_Internal = 1; > > my $exp; > > $exp = new Expect (); > > $exp->raw_pty(1); > > $exp = Expect->spawn("/usr/bin/less", "/tmp/crap") or die "Cannot spawn > client: $!\n"; > > $exp->log_file( "/tmp/exp.out", "w" ); > > $exp->expect($timeout, "crap" ); > print "done expect.\n"; > > $exp->send("\c[[B"); > $exp->send("\c[[B"); > $exp->send("\e[B"); > > $exp->expect($timeout, "26" ); > > sleep 5; > > print "done arrows.\n"; > > $exp->send("j"); > $exp->send("j"); > $exp->send("j"); > sleep 5; > > $exp->expect($timeout, "26" ); > > $exp->send("q"); > sleep 5; > > $exp->expect($timeout, "crap" ); > > print "Done sending.\n"; > > - ---------------------- > > As you can see, the arrow keys do nothing, but the j keys work just > fine. > > -Robin Ok i think i fixed your issue, which appears to be a termcap problem. Try running any one of your scripts, but change your TERM environment variable to one of vt220, linux, putty, sun, cygwin, or asni (looks like crap but works) and you should be fine. There are probably more, but those are the ones i tested that worked. Hope that helps. Bryan Bueter http://sourceforge.net/projects/rover |
From: Robin L. P. <rlp...@di...> - 2008-12-12 20:07:33
|
On Fri, Dec 12, 2008 at 11:17:55AM -0500, Bryan Bueter wrote: > Ok i think i fixed your issue, which appears to be a termcap > problem. Try running any one of your scripts, but change your > TERM environment variable to one of vt220, linux, putty, sun, > cygwin, or asni (looks like crap but works) and you should be > fine. Well spank my ass and call me charlie! I tried TERM=vt100 and then pretty much gave up on that line of inquiry. That's *great*! Thank you so much! -Robin -- They say: "The first AIs will be built by the military as weapons." And I'm thinking: "Does it even occur to you to try for something other than the default outcome?" -- http://shorl.com/tydruhedufogre http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/ |