Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Interact with mainframe screen

by Anonymous Monk
on Apr 19, 2007 at 21:14 UTC ( #611038=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Im not even sure where to begin. Im fairly new to Perl. I want to be able to automate key strokes to the mainframe while on a terminal connection. Basically I want to emulate a regular mainframe session where they input data into the different screens. Where can I find information about this? Any help would be greatly appreciated. Thanks for your time. Sincerely, Paul

Comment on Interact with mainframe screen
Re: Interact with mainframe screen
by GrandFather (Cardinal) on Apr 19, 2007 at 21:25 UTC

    How about a little information. Like, how does your "terminal" communicate to the "mainframe". Are we talking about an old RS-232 terminal or a dedicated terminal for some arcane mainframe or a virtual terminal running over a lan or something else?

    What are you suggesting as a replacement for the terminal? A Windows box, a *nix box, the current "terminal" running a smarter editor, something else?


    DWIM is Perl's answer to Gödel
      Sorry, I left out some of that information. We currently input information through (hummingbird->HostExplorer)3270 terminal emulator on our desktop. If possible I would like to automate the inputs using a perl script.
        Ah. It's been a while since I played with Hummingbird, but I seem to recall that it has both VT100 and TN3270 APIs available. Depending on which kind of terminal the mainframe expects to be talking to, you will be able to use the 'native' API-calls to scrape the data into a character string that you can manipulate with Perl.

        ----
        I Go Back to Sleep, Now.

        OGB

Re: Interact with mainframe screen
by Old_Gray_Bear (Bishop) on Apr 19, 2007 at 21:35 UTC
    As Grandfather pointed out, it depends on the terminal. It also depends on the application, as well. If you are trying to interact with a TSO/ISPF application, then you might have much better luck using REXX rather than Perl.

    (There. Finally. A thread where both the Old Guys responded!)

    ----
    I Go Back to Sleep, Now.

    OGB

      Yes Im trying to interact with TSO and ISPF. So this isnt doable with Perl?
Re: Interact with mainframe screen
by roboticus (Canon) on Apr 20, 2007 at 03:16 UTC
    You might try using the x3270 (or was it s3270?) program, which is an open-source IBM 327x terminal emulator. It has a scripting part that you can use in it, so you should be able to drive it with a perl program.

    I don't know where to get the original project, as I got it as a package in cygwin. It worked well when I had a need to hit our mainframe a couple of years back.

    ...roboticus

Re: Interact with mainframe screen
by Corion (Pope) on Apr 20, 2007 at 06:55 UTC

    I automate 3270 applications from Perl by using the IBM Personal Communications 3270 terminal emulator on Win32 via Win32::OLE. It is very well documented and it works very good.

    As an alternative if you are not on Win32, consider looking into s3270 resp. x3270 for automating your program, but these do not provide the good API that IBM does.

    Here is a short extract I use to initialize and start a session:

    package Host::PCOM; use strict; use Carp qw(croak carp); use Logger; use Win32; use Win32::OLE; Win32::OLE->Option( Warn => 3 ); sub new { my ($class,$connection_name) = @_; my $self = {}; bless $self, $class; $self->log("Creating connection manager"); my $connmgr = Win32::OLE->new("PCOMM.autECLConnMgr") or die "Couldn't create PCOMM.autECLConnMgr : $!\n"; $self->log("Creating session"); my ($session) = Win32::OLE->new("PCOMM.autECLSession") or die "Couldn't create PCOMM.autECLSession $!\n"; # Now connect the session my $session_info; $session_info = $connmgr->{autECLConnList}->FindConnectionByName($co +nnection_name); unless ($session_info) { $self->log("Personal Communications not found running. Starting se +ssion"); #my $hostname = Win32::NodeName; my $hostname = 'WSConfig'; $connmgr->StartConnection("profile=$hostname connname=$connection_ +name"); my ($count) = 20; while (! $session_info and $count--) { $connmgr->{autECLConnList}->Refresh(); $session_info = $connmgr->{autECLConnList}->FindConnectionByName +($connection_name); #sleep(2); select undef, undef, undef, 0.5 unless $session_info; }; sleep(5); }; die "Couldn't find or start session $connection_name\n" unless $session_info; $session->SetConnectionByHandle( $session_info->{Handle} ); my $ECLOIA = $session->autECLOIA(); die "Couldn't get ECLOIA : $!" unless $ECLOIA; my $ECLPS = $session->autECLPS(); while (! $session->Started) { $ECLPS->Wait(500); }; if (! $session->CommStarted) { $session->StartCommunication; while (! $session->CommStarted) { $ECLPS->Wait(500); }; }; $self->{conn} = $connmgr; $self->{session} = $session; $self->{ecloia} = $ECLOIA; $self->{eclps} = $ECLPS; $self; }; ... much domain specific code following which I won't post ...
      Thank you for this bit of code... Everyone is so helpful in here. I will let you know how it goes. Thanks again everyone! Sincerely, Paul
      Could specify where I would use my login information to log into the mainframe? Im guessing $connection_name = login and password? Whats the exact syntax? and what is $profile, is it a file it reads from or is it a variable I assign?

        The above code is only the package to launch the connection to the 3270 window, not to give any input to it. I recommend that you read the documentation that accompanies IBM Personal Communications to find out how to automate stuff within it. I won't post my complete code as much of it belongs to my employer I guess. You will then need to employ the methods to read what is on the screen and which fields are available for input. For example, I have the following subroutine in Host::PCom:

        sub screen { my ($self) = @_; my ($cols,$rows) = ($self->cols,$self->rows); my ($line) = $self->eclps->GetTextRect(1,1,$rows,$cols); my @lines; while ( $line =~ s/(^.{1,$cols})//sm) { push @lines, $1; }; s!\0! !g for @lines; # Mark fields as dirty $self->log("Fields marked dirty"); $self->{fields} = undef; push @lines, $line if $line; @lines; };

        It returns the current screen (resp. a cached version of it) as a list of scalars which my programs then check. I also have two routines for getting and setting input fields:

        sub get_set_field { my $self = shift; my $field = shift; my $result; if (defined wantarray) { $result = $field->GetText(); $self->log("value is $result"); carp( "get_set_field() called in void context without a value",2 ) + unless @_; }; if (@_) { $field->SetText(@_); $self->log("Setting field to @_"); }; $result; }; sub field_by_index { my $self = shift; my $index = shift; my @fields = $self->fields; my $field = $fields[ $index ]; $self->get_set_field($field,@_); };
      Thanks for the script and pointing out the COM interface to IBM's Personal Communications. I doubt I would have been able to complete a project at work w/o your post...hacker in SD.
      Hi, I am very interested in your solution of using OLE for perl access to the mainframe. I am trying to extend our (AIX/Windows based) environment for automated testing to the mainframe area. I have started work on a perl module that uses the Expect module on AIX to use the tn3270 emulator. But I think your approach is much better. I will try and see if I can use it with the 3270 emulator in our environment. The piece of code that you posted shows that it is a Host::PCOM module. Is it freely available? From your statement at the bottom I guess it is not. Is there a possibility for you to strip out the specific parts for your environment and publish the generic parts? I would be pleased to use it as a basis for further development and to help make this a general available perl module.

        No. Host::PCOM is a module I developed on the time and entirely for my employer. I don't feel it would be right to redistribute that code on my own, and I won't take it on me to involve the lawyers to get a release from my employer.

        That being said, it's not really hard to encapsulate the OLE API, as IBM provides plenty of good documentation.

      The documentation on available classes and methods for IBM Personal Communications 3270 through OLE is available on IBM site.

      Hope this can help someone, as I used it a lot to implement something equivalent to what Corion did.

Re: Interact with mainframe screen
by jeepj (Scribe) on Mar 14, 2008 at 08:35 UTC

    I am also using the OLE interface to target PCOMM sessions, but with more than 3 or 4 sessions, some get stuck and scripts end with an OLE exception (saying that session is locked). Thus I was looking on Google to know why, and I found something interesting: starting with version 4.x (don't know exactlty which version), an interface is provided as a DLL (EHLLAPI.dll) for C or Java. I'm currently trying to use it in Perl with Win32::API. If I manage to make it working, I'll put something in code Snippets.

    UPDATE: You can find an example in mainframe screen - PCOMM - EHLLAPI

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://611038]
Approved by GrandFather
Front-paged by jdporter
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-10-26 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (152 votes), past polls