Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm trying to write a script which will (upon completion), navigate through records maintained on an IBM mainframe using a tn3270 terminal, and scrape said records into html files for later manipulation.
Commands are emulator actions; the syntax is the same as for the right-hand side of an Xt translation table entry (an x3270 or c3270 keymap). Unlike translation tables, action names are case-insensitive, can be uniquely abbreviated, and the parentheses may be omitted if there are no parameters. Any input line that begins with # or ! is treaded as a comment and will be ignored.
However, when i call the above using the script() function in s3270, the script prints to stdout, but the actions are not executed as expected.
For example:
Code:
(NOTICE: I've shortened the script for example's sake)
$ s3270
script(/path/to/my/script/test.3270)
connect(L:ssl3270.myhost.org:2023)
ascii()
string(command1)
enter()
ascii()
L U U N N 4 24 80 0 0 0x0 -
ok
Expected output would've been (for starters) the first character of the status string changing to U (as the keyboard should unlock when i am connected), and the initial screen printed in ascii, a command sent, and the resulting screen printed in ascii as well.
I'm not sure what i am doing wrong. Can someone give me an example script that works? Something simple that depicts how i can use something like bash, perl, or python to send commands to this application and navigate through screens.
Thanks in advance
Last edited by doomed9; 11-05-2009 at 10:14 AM..
Reason: pointing out that the script i executed has been shortened from the example i gave earier in the post
This is a bash script that, if called from within s3270, will navigate to the application login page and create html files of each page along the way.
while x3270if is nice, i reckon i expected a simpler solution...something easier to use with a language's built-in functionality.
What would i do with perl? Hopefully not make a call to system() each time i want to input data. Is there a way to treat the terminal connection as a file handle and just send commands to it via print()?
Thank you for the excellent referral. I was on the right track to my answer in a few minutes...
Using perl's IPC::Run module, i was able to pipe commands directly to the s3270 subprocess. Thus, the below is an example of x3270's peer script facility:
Code:
#!/usr/bin/perl
my @s3270 = s3270;
use IPC::Run qw( start pump finish timeout );
$IPCRUNDEBUG=details;
# Incrementally read from / write to scalars.
# $in is drained as it is fed to s3270's stdin,
# $out accumulates s3270's stdout
# $err accumulates s3270's stderr
# $h is for "harness".
my $h = start \@s3270, \$in, \$out, \$err, timeout( 10 );
$in .= "connect(L:ssl3270.myhost.org:2023)\n";
$in .= "ascii\n";
$in .= "quit";
finish $h or die "s3270 returned $?";
warn $err if $err;
print $out; ## All of cat's output
hope this helps any googlers interested in scripting with s3270.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.