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 ...

In reply to Re: Interact with mainframe screen by Corion
in thread Interact with mainframe screen by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.