Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Controlling a TTY via screen position

by mutt (Novice)
on Dec 12, 2008 at 17:16 UTC ( #729982=perlquestion: print w/replies, xml ) Need Help??
mutt has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to automate a session which uses 5250 emulation. This (that I'm aware of) cannot be achieved through traditional means like Net::Telnet or anything due to the nature of the protocol.

I want to spawn a console app (such as tn5250) and then use screen positions to input and read text.

I cannot for the life of me figure out how to get started.

Term::Cap just writes plainly to a terminal. IO:Pty doesn't seem to fit

I'm simply lost for the moment. I was hoping for a nudge in the right direction.

Replies are listed 'Best First'.
Re: Controlling a TTY via screen position
by jbert (Priest) on Dec 13, 2008 at 09:43 UTC

    OK. If you're on Linux, then the tn5250 app is reading from stdin. You should be able to drive it as a child process via IO::Pty (or open2/open3)and send it the same escape sequences that it expects to see.

    e.g., to simulate pressing an up arrow to tn5250, you'll send a short character sequence to it's standard input.

    You can work out which chars to send by hitting the docs or just running tn5250 under 'strace' and seeing it reads from fd 0 (the read(0, "...") bit when you hit the key.

    You'll get the screen contents back from the stdout of the tn5250 process. These will contain escape sequences suitable for the terminal which tn5250 thinks you're running (probably vt100), which you could interpret and write the data at the appropriate offset in a screen buffer.

    So, you'll end up emulating keystrokes to the tn5250 and understanding the escape sequences it sends back, so not a trivial task. It's perhaps also one which is prone to deadlock, if you're doing blocking reads from the app, so you'll probably want to use nonblocking reads if you can.

    Maybe I've misunderstood, but I think that's what would be required. (Well, or re-implementing the 5250 network protocol your console app uses, or pulling apart the console app so you can call into it as a C API wrapped in XS, or adding (or finding) an existing scripting mechanism for this app, or...

    Ah...CPAN goodness, there's Term::VT102 which might help a lot.

Re: Controlling a TTY via screen position
by CountZero (Bishop) on Dec 13, 2008 at 15:04 UTC
    There is an old sourceforge project for a tn5250 terminal emulator over telnet.

    Perhaps by studying the sourcefiles you can learn more about this protocol. The project also has some termcap and terminfo files which detail the codes used to drive the terminal.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Controlling a TTY via screen position
by Anonymous Monk on Dec 13, 2008 at 04:47 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://729982]
Approved by mr_mischief
Front-paged by Sinistral
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-01-22 20:34 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (237 votes). Check out past polls.