TheSavoy has asked for the wisdom of the Perl Monks concerning the following question:
I've been given the task of taking screen dumps from an old IBM mainframe. I found a script-friendly terminal emulator called s3270 - great little program. I've managed to write a script in bash to connect to the mainframe, navigate to the login screen, and scrape each screen in between into an html file.
#!/bin/bash file_path="/path/to/my/files" date=$(date +"%Y%m%d%H%M%S") x3270if "connect(L:ssl3270.myhost.org:2023)" x3270if "printtext(html,file,$file_path/myhost-$date.html)" x3270if "string(command1)" x3270if "enter" x3270if "printtext(html,file,$file_path/myhost-$date.html)" x3270if "enter" x3270if "string(command2)"
This is great, if it wasn't for the fact that this is in bash, and lacks the string manipulation power that i could have in perl. This is also what x3270-script calls "the child script facility", and i quote:
invoked by the Script action in x3270, c3270, or s3270. This runs a script as a child process of the emulator. The child has access to pipes connected to the emulator; the emulator look for commands on one pipe, and places the responses on the other. (The file descriptor of the pipe for commands to the emulator is passed in the environment variable X3270INPUT; the file descriptor of the pipe for responses from the emulator is passed in the environment variable X3270OUTPUT.)What this means, is that I have to launch s3270, then from within that, i can start my script. This makes it difficult to fully automate the program, since launching s3270 from within my script causes the rest of the instructions to wait for s3270 to close (complete and utter failure)
What I'm really looking for, is the ability to use the "peer script facility". Let the man page explain:
the peer script facility, invoked by the x3270 -script switch, and the + default mode for s3270 and ws3270. This runs x3270, s3270 or ws3270 +as a child of another process. Typically this would be a script using + expect(1), perl(1), or the co-process facility of the Korn Shell ksh +(1). Inthis mode, the emulator process looks for commands on its stan +dard input, and places the responses on standard output and standard +error output.
What I need, is to write a script that will spawn an s3270 process, and be able to send commands to it. I _think_ there is some way to treat a process like a file handle, and send commands to it in perl via print. This is, of course, hearsay from various forums that talk about the ability to do such a thing, but lack proper proof that it works. Here's an example of what i'd like the end result to be:
#!/usr/bin/perl sub launch_s3270 { # Some magic to launch s3270 as a child process and retain the ability + to write to it } sub connect_3270 { print $s3270 "connect(L:ssl3270.myhost.org:2023)"; }
If someone can just help me with the first part, i think the rest would be downhill. I've been a perl programmer for several years now, but this is a relatively new concept to me, as far as the capabilities of perl. Any help would be appreciated.
Thank You!
P.S.: I'm looking for the simplest way to do this. If my suggested train of thought is not the brightest, feel free to correct me
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: scraping screens from a tn3270 terminal
by Corion (Patriarch) on Nov 07, 2009 at 16:45 UTC | |
by TheSavoy (Initiate) on Nov 07, 2009 at 22:05 UTC |