From: Paulo R. <pa...@se...> - 2002-12-03 15:43:40
|
Hi, i´m from Brazil, and i try make interface program (with terminal 3270) to web... I have so problem, may someone could help me.... I need execute e send commands to program, and pick up the screen and show to user in web... Execute i can, but pick up the screen and send command i don´t know Down have the script ... Thanks the script has write by Va...@Di... but in the line 161 or show me a error $x3270->expect(60,'-re','data: .*') || die "Unexpected error in x3270_ascii"; $s=$x3270->exp_match(); use Expect; $Expect::Log_Stdout=0; # On by default. # #====================================================================== # timeout print an error message and exit #====================================================================== # sub timeout { print STDERR "Unexpected timeout\n"; exit 2; } # #====================================================================== # x3270_die print the last AS400 screen and die #====================================================================== # sub x3270_die { my $s; print STDERR "----------- Last AS/400 Screen\n"; $s=x3270_asciiscreen(); print STDERR "$s"; print STDERR "-------------------------------\n"; print STDERR @_; die; } # #====================================================================== # x3270_connect Connet to the AS400 (only connection no logon) # return 1 on success, 0 on failure #====================================================================== # sub x3270_connect { print STDERR "Connecting to: $as400\n"; print $x3270 "Connect($as400)\n"; print $x3270 "Wait()\n"; unless ($x3270->expect(30,'-re', "U F U C.$as400.*")) { return 0; } print STDERR "-->x3270_connect: connected\n"; return 1; } # #====================================================================== # x3270_login logon to the AS400 # return 1 on success, 0 on failure #====================================================================== # sub x3270_login { my $corb=x3270_ascii(1,69,8); my ($scr,$days); print STDERR "Findig S65DD4AA found:$corb:\n" if $debug; if ($corb ne "S65DD4AA") { print STDERR "-->x3270_login: Login Screen not found\n"; return 0; }; print STDERR "-->x3270_login: Found Login screen\n"; print $x3270 "String($user)\nTab()\nString($password)\nEnter()\n"; ###### ### skip unusual screens ###### $scr= x3270_asciiscreen(); while ($scr =~ /Press Enter to continue/m) { print $x3270 "Enter()\n"; print STDERR "-->x3270_login: Sent Enter to continue\n"; $scr=x3270_asciiscreen(); } ### end of skipping unusual screens $_=&x3270_ascii(0,32,16); if ($_ ne "AS/400 Main Menu") { print STDERR "-->x3270_login: AS/400 main menu not found\n"; return 0; } print STDERR "-->x3270_login: found AS/400 Main Menu\n"; return 1; } # #====================================================================== # x3270_asciiscreen return in a multiline string the full # AS400 screen (25 rows x 80 columns) #====================================================================== # sub x3270_asciiscreen { return x3270_asciiregion(0,0,24,79); } # #====================================================================== # x3270_asciiregion return in a multiline string of a region of # the AS/400 screen. # Input parameters: # $r starting row (0 ... 24) # $c starting column (0 .. 79) # $rlen region width # $clen region height #====================================================================== # sub x3270_asciiregion { my ($r,$c,$rlen,$clen) = @_; my ($res,$i); print STDERR "--> x3270_asciiregion (r,c,rlen,clen)=$r,$c,$rlen,$clen\n" if $debug; $res=''; for $i ($r .. $r+$rlen-1) { $res .= x3270_ascii($i,$c,$clen); $res .= "\n"; } print STDERR "-->x3270_asciiregion begin ----\n" if $debug; print STDERR $res if $debug; print STDERR "-->x3270_asciiregion end ----\n" if $debug; return $res; } # #====================================================================== # x3270_ascii return an ascii string from the screen # input parameters # $r starting row (0 .. 24) # $c starting column (0 .. 79) # $len string length #====================================================================== # sub x3270_ascii { my ($s,$t); $t=$"; $"=','; print STDERR "--x3270_ascii-->Sending: Ascii(@_)\n" if $debug; print $x3270 "Ascii\n"; sleep(20); $"=$t; print $teste; sleep(20); $x3270->expect(60,'-re','data: .*') || die "Unexpected error in x3270_ascii"; $s=$x3270->exp_match(); chomp $s; print STDERR "--x3270_ascii-->Matching string\n:",$s,":\n***\n" if $debug; $s=~s/data: (.*).$/$1/; print STDERR "--x3270_ascii-->Returning\n:",$s,":\n***\n\n" if $debug; return $s; } # #====================================================================== # x3270_gencmd Execute a generic command, it does expect that after # executing the command to receive a command prompt # input parameters # $cmd command string (example "addlible toollib") #====================================================================== # sub x3270_gencmd { my $cmd=$_[0]; print STDERR "-->x3270_gencmd: $cmd\n"; print $x3270 "String(\"$cmd\")\nEnter()\n"; my $str=x3270_ascii(19,0,5); if ($str eq ' ===>') { return 1; } else { print "-->x3270_gencmd str: $str\n"; return 0; } } # #====================================================================== # x3270_prtflayout print file layout #====================================================================== # sub x3270_prtflayout { my($lib,$file)=@_; x3270_gencmd("addlible toollib *last") || x3270_die("Error in addlible\n"); x3270_gencmd("prtffd file($lib/$file)") || x3270_die("Error in prtffd\n"); } # #====================================================================== # x3270_getsplflist gives the "wrksplf" command and return # an array of hashes; each element in the array # is for each spool file; each hash as the # following keys: file, user, device, userdata, # sts, totalpages, formtype, pty, # cdate, ctime, filenbr, job, # number, queue, library # input parameters # $usersplf parameters to the wrksplf command # #====================================================================== # sub x3270_getsplflist { my $usersplf=$_[0]; print STDERR "--->x3270_getsplflist\n"; my ($s,%e,@e,@lst,$void); print $x3270 "String(\"wrksplf $usersplf\")\nEnter()\n"; my $scr1=x3270_asciiscreen(); print STDERR "(0)\n"; my $firsttime=1; while (($scr1=~/\s+More\.\.\./m) or ($firsttime)) { $firsttime=0; $scr1=x3270_asciiscreen(); print STDERR "(0b)\n"; if (not $scr1=~"Work with All Spooled Files") { print STDERR "(0c)\n"; x3270_die("Error in wrksplf\n"); } print STDERR "(2)\n";sleep(1); print $x3270 "PA(1)\nPF(11)\n"; my $scr2=x3270_asciiscreen(); print STDERR "(3)\n"; sleep(1); print $x3270 "PA(1)\nPF(11)\n"; my $scr3=x3270_asciiscreen(); my @scr1=split /\n/m,$scr1; my @scr2=split /\n/m,$scr2; my @scr3=split /\n/m,$scr3; for $i (0 .. scalar @scr1) { if ($scr1[$i]=~/^ [A-Z]/) { @e=split /\s+/,$scr1[$i]; ($void,$e{file},$e{user},$e{device},$e{userdata},$e{sts}, $e{totalpages})=@e; @e=split /\s+/,$scr2[$i]; ($void, $e{file},$e{user},$e{formtype},$e{pty},$e{cdate}, $e{ctime})=@e; @e=split /\s+/,$scr3[$i]; ($void,$e{file},$e{filenbr},$e{job},$e{user},$e{number},$e{queue}, $e{library})=@e; push @lst,{ %e }; } } print $x3270 "PA(1)\nPF(11)\n"; print $x3270 "PA(1)\nPF(11)\n"; print $x3270 "PF(8)\n"; } print $x3270 "PA(1)\nPF(3)\n"; @x3270_splflst=@lst; } # #====================================================================== # x3270_dspffd return a mutiline string: the output of the # dspffd (display file field description) command # input parameters: # $library # $file #====================================================================== # sub x3270_dspffd { my ($library,$file)=@_; my ($s,$scr,@scr,$firsttime); print STDERR "--->x3270_dspffd\n"; print $x3270 "String(\"dspffd file($library/$file)\")\nEnter()\n"; my $scr=x3270_asciiscreen(); print STDERR "(0)\n"; $firsttime=1; $s=""; while (($scr=~/\s+More\.\.\./m) or ($firsttime)) { $firsttime=0; $scr=x3270_asciiscreen(); print STDERR "(0b)\n"; if (not $scr=~"Display Spooled File") { print STDERR "(0c)\n"; x3270_die("Error in dspffd\n"); } print STDERR "(2)\n";sleep(1); @scr=split /\n/m,$scr; $s=$s . join("\n",@scr[5 .. 20]) . "\n"; print $x3270 "PF(8)\n"; } return $s; } 1; Down have the main program use Getopt::Std; require "as400-include.pl"; $|=1; # #====================================================================== # Process options #====================================================================== # #getopts('u:p:l:f:d:x'); #if (not ($opt_u and $opt_p and $opt_l and $opt_f)) { # usage(); # exit; #} $debug="0"; $user="LUIS"; $upuser= uc $user; $password="10"; $as400="nerdc.ufl.edu:23"; $library="file"; $uplibrary=uc $library; $file="teste"; $upfile=uc $file; #if ($opt_x) { # $x3270cmd="x3270 -script -model 2 -color"; #} else { $x3270cmd="/home/paulo/s3270-3.2/s3270 -model 2"; #} # #====================================================================== # usage #====================================================================== # #sub usage { # print STDERR "usage: $0 [-d debuglevel] [-x] -u userid -p password -l library -f file\n"; # print STDERR " debuglevel a value between 0-9\n"; # print STDERR " -x display the x3270 window emulator\n"; #} # #====================================================================== # ffd2layout File field description to layout # input # $sin string output of the x3270_dspffd function # returned value # string in my own layout format # #====================================================================== # sub ffd2layout { my $sin=$_[0]; my ($s,$sout,$fname,$firsttime); my ($fname,$ft,$flng,$frlen,$ffrm,$fto); my %tb = ( CHAR => 'A', PACKED => 'P', ZONED => 'S' ); $sout=""; my @sin=split("\n",$sin); # ##### skip to the beginning of field descriptions # do { $s=shift @sin; } until ($s=~'Field Type Length Length Position Usag'); # ##### extract field definitions # $firsttime=1; while (defined ($s=shift @sin)) { if ( $s=~/^ (\S.........) (\S........) (...)(...) (......) (......)/ # "^ (\PLANN ) (\PACKED ) ( 5)( 0) ( 3) ( 51) ) { if (not $firsttime) { $sout .= sprintf(" %-10s %-36s %-1s %+3s %+2s %+6s %+6s %+4s\n", $fname,$fdescr,$tb{$ft},$flng,$fdc,$frlen, $ffrm,$fto); undef $fdescr; } else { $firsttime=0; } $fname=$1; # field name $ft=$2; # field type $flng=$3; # field lenght $fdc=$4; # field num. of decimals $frlen=$5; # field real (num of bytes) length $ffrm=$6; # field starting position (from) $fto=$ffrm+$frlen-1; #field ending position (to) $ft=~s/ +$//; if ($flng eq ' ') { $flng=$fdc; $fdc=""; } else { $fdc=substr($fdc,-2); } } elsif ($s=~/^ Field text [\. ]+:\s+(.*)$/) { $fdescr=$1; $fdescr=substr($fdescr,0,36); } } $sout .= sprintf(" %-10s %-36s %-1s %+3s %+3s %+6s %+6s %+4s\n", $fname,$fdescr,$tb{$ft},$flng,$fdc,$frlen, $ffrm,$fto); return $sout; } # #====================================================================== # Main program #====================================================================== # $x3270 = Expect->spawn($x3270cmd) || die "error spawning x3270\n"; sleep(2); x3270_connect() || x3270_die("Didn't connect\n"); x3270_login() || x3270_die("Cannot login\n"); $s=x3270_dspffd($library,$file) || x3270_die("Error executing dsptrk\n"); print ffd2layout($s); exit; Paulo season.com.br |