From: Roland G. <RGi...@cp...> - 2006-04-21 08:38:43
|
Quoting "Mopuri, Shailaja" <sha...@in...>: > Hi, > I am trying to invoke telnet using Expect from Perl in Cygwin. The > same > code works in Linux systems which means there is something different > when invoked from Cygwin shell. Can anyone suggest any workarounds or > suggestions to fix this issue. What are the symptoms of the failure? Any error messages? "This does not work" is not an allowed problem-description for a technician... :-) Alternatively you could try to use Net::Telnet to connect and pass its filehandle to exp_init, so you would avoid the cygwin shell and ptys alltogether. > Below is the sample code that I am trying to get it work > > Thanks, > Shailaja > > #!/usr/bin/perl > > # use module > use XML::Simple; > use Expect; > > #Create the Expect handle > $Expect_Handle =3D new Expect; > $Cmds =3D "telnet atsism01 623"; > $Responses =3D "server:"; > $Result =3D $Expect_Handle->spawn($Cmds."\n"); Why the "\n"? This would make the last argument "623\n" (if the shell wouldn't strip whitespace). > # Clears the previous output accumulated incase of match failures > $Expect_Handle->clear_accum(); > $Pattern_ID =3D $Expect_Handle->expect($Timeout,'-re', $Responses); > #Capture the current prompt > $Current_Prompt =3D $Expect_Handle->match(); > #Capture the output > $ActualOutput =3D $Expect_Handle->before().$Current_Prompt; > =09 > -- RGi...@cp... |