From: Schuller, B. <Bil...@in...> - 2003-11-17 21:38:24
|
I use this regex to match for shell prompts: $shell_prompt= '(.*%|.*#|.*>|.*\\$) $'; and call expect like so: $obj_name->expect($timeout, '-re', $shell_prompt); It works with most prompts (I've tested on bash, sh, ksh and tcsh on Solaris, Windows (Cygwin) and Tru64 boxes with many users' funky prompts) that I have come across and doesn't interfere with any other data I've run into either. Bill Schuller Bil...@in... bi...@wu... -----Original Message----- From: Benjamin [mailto:mai...@sa...] Sent: Friday, November 14, 2003 3:51 PM To: exp...@li... Subject: [Expectperl-discuss] Perl Expect and sh Hi all, I'm trying to play with Perl-Expect and I'm not having much success getting it to do a simple task. Here is the code: use Expect; $Expect::Exp_Internal = 1; my $exp = Expect->spawn("/bin/sh") or die "Cannot spawn /bin/bash: $!\n"; #print "got here\n"; $exp->expect(10, "sh"); $exp->send("ls \n"); With it, I'm trying to spawn sh and then do an ls (I know I can do ls directly, but I'm trying it this way for this example), but when I do this, I get the following output: Spawned '/bin/sh' spawn id(3) Pid: 5442 Tty: /dev/pts/2 Expect::spawn('Expect','/bin/sh') called at test.pl line 5 Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x806479c)',10,'sh') called at test.pl line 8 spawn id(3): list of patterns: #1: -ex `sh' spawn id(3): Does `' match: pattern #1: -ex `sh'? No. Waiting for new data (10 seconds)... sh-2.05b$ spawn id(3): Does `sh-2.05b$ ' match: pattern #1: -ex `sh'? YES!! Before match string: `' Match string: `sh' After match string: `-2.05b$ ' Matchlist: () Returning from expect successfully. Sending 'ls \n' to spawn id(3) Expect::print('Expect=GLOB(0x806479c)','ls \x{a}') called at test.pl line 9 [userid@machineid userid]$ Without getting a list of the files. Any help is appreciated. I am using RedHat 9.0 with the latest expect modules from CPAN.org. Thanks, Ben ------------------------------------------------------- This SF. Net email is sponsored by: GoToMyPC GoToMyPC is the fast, easy and secure way to access your computer from any Web browser or wireless device. Click here to Try it Free! https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |