X3270-SCRIPT(1)
π X3270-SCRIPT(1) π
From General Commands Manual, bestie β this is the scripting-facilities page for x3270, c3270, and s3270. Buckle up, because itβs giving βyour terminal has main character energyβ β¨
πΈ NAME πΈ
Scripting Facilities for x3270, c3270 and s3270
β¨ SYNOPSIS β¨
x3270 -script [ x3270-options ]
x3270 -socket [ x3270-options ]
x3270 -scriptport port [ x3270-options ]
c3270 -socket [ c3270-options ]
c3270 -scriptport port [ s3270-options ]
s3270 [ s3270-options ]
Script ( command [ ,arg... ] )
π¦ DESCRIPTION π¦
Okay so the x3270 scripting facilities are how you let another program drive the interactive 3270 emulators x3270 and c3270. Theyβre also literally the whole foundation of s3270, the script-only emulator. π
There are four basic scripting methods, bestie:
- The first is the peer script facility, invoked by the
x3270 -scriptswitch, and itβs the default mode fors3270. This runs the emulator as a child of another process. Typically that other process is a script usingexpect(1),perl(1), or the co-process facility of the Korn Shellksh(1). In this mode, the emulator process looks for commands on its standard input and puts the responses on standard output. π«Ά - The second method is the child script facility, invoked by the emulatorβs
Script()action. This runs a script as a child process of the emulator. The child gets pipes connected to the emulator: the emulator looks for commands on one pipe and puts responses on the other. The file descriptor of the pipe for commands to the emulator is passed in the environment variableX3270INPUTβ for example, the text string"7"if the file descriptor is7. The file descriptor of the pipe for responses from the emulator is passed in the environment variableX3270OUTPUT. π - The third method uses a TCP socket. The
-scriptportoption from the synopsis (the DESCRIPTION text in this page spells it-scrpiptportonce, so π spelling-check energy) causes the emulator to bind a socket to the specified port on the IPv4 loopback address,127.0.0.1. The emulator accepts TCP connections on that port, and multiple commands and responses can be sent over each connection. π - The fourth method uses a Unix-domain socket. The
-socketcommand-line option causes the emulator to create a Unix-domain stream socket named/tmp/x3sck.pid. The emulator accepts connections to that socket, and multiple commands and responses can be sent over each connection. π¦
You can nest these methods, no cap. For example, a peer or TCP socket script can invoke the Script() action. The calling script will be resumed when the nested script completes. π₯
Commands are emulator actions. The syntax is the same as for the right-hand side of 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 treated as a comment and will be ignored. π
Any emulator action may be specified. Several specific actions have been defined for use by scripts, and the behavior of certain other actions β and of the emulators in general β is different when an action is initiated by a script. π
Some actions generate output; some may delay completion until certain external events occur, such as the host unlocking the keyboard. The completion of every command is marked by a two-line message. The first line is the current status of the emulator, documented below. If the command is successful, the second line is the string "ok"; otherwise it is the string "error". π
π STATUS FORMAT π
The status message consists of 12 blank-separated fields:
- Keyboard State β If the keyboard is unlocked, the letter
U. If the keyboard is locked waiting for a response from the host, or if not connected to a host, the letterL. If the keyboard is locked because of an operator error (field overflow, protected field, etc.), the letterE. - Screen Formatting β If the screen is formatted, the letter
F. If unformatted or in NVT mode, the letterU. - Field Protection β If the field containing the cursor is protected, the letter
P. If unprotected or unformatted, the letterU. - Connection State β If connected to a host, the string
C(hostname). Otherwise, the letterN. - Emulator Mode β If connected in 3270 mode, the letter
I. If connected in NVT line mode, the letterL. If connected in NVT character mode, the letterC. If connected in unnegotiated mode (no BIND active from the host), the letterP. If not connected, the letterN. - Model Number (2-5)
- Number of Rows β The current number of rows defined on the screen. The host can request that the emulator use a 24x80 screen, so this number may be smaller than the maximum number of rows possible with the current model.
- Number of Columns β The current number of columns defined on the screen, subject to the same difference for rows, above.
- Cursor Row β The current cursor row (zero-origin).
- Cursor Column β The current cursor column (zero-origin).
- Window ID β The X window identifier for the main
x3270window, in hexadecimal preceded by0x. Fors3270andc3270, this is zero. - Command Execution Time β The time that it took for the host to respond to the previous command, in seconds with milliseconds after the decimal. If the previous command did not require a host response, this is a dash. β
π DIFFERENCES π
When an action is initiated by a script, the emulators behave in several different ways:
- If an error occurs in processing an action, the usual pop-up window does not appear. Instead, the text is written to standard output. π«Ά
- If end-of-file is detected on standard input, the emulator exits. A script can exit without killing the emulator by using the
CloseScript()action, below. Note that this applies to peer scripts only; end-of-file on the pipe connected to a child script simply causes the pipes to be closed and theScript()action to complete. π - The
Quit()action always causes the emulator to exit. When called from the keyboard, it will exit only if not connected to a host. π - Normally, the AID actions (
Clear(),Enter(),PF(), andPA()) will not complete until the host unlocks the keyboard. If the parameter to aString()action includes a code for one of these actions, it will also wait for the keyboard to unlock before proceeding. β¨οΈ - The
AidWaittoggle controls this behavior. When this toggle is set (the default), actions block as described above. When the toggle is clear, AID actions complete immediately. TheWait(output)action can then be used to delay a script until the host changes something on the screen, and theWait(unlock)action can be used to delay a script until the host unlocks the keyboard, regardless of the state of theAidWaittoggle. π - Note that the
Script()action does not complete until end-of-file is detected on the pipe or theCloseScript()action is called by the child process. This behavior is not affected by the state of theAidWaittoggle. β¨
π BASIC PROGRAMMING STRATEGIES π
3270 session scripting can be more difficult than other kinds of scripting, because it can be hard to tell when the host is finished processing a command. There is a well-defined 3270 Data Stream facility for doing this: the emulator locks the keyboard when it sends the host an AID, and the later host unlocks the keyboard. The emulator supports this facility directly by not allowing an AID action to complete until the keyboard is unlocked. π
Unfortunately, some hosts and some host applications unlock the keyboard as soon as they begin processing the command, instead of after it is finished. A human operator can see on the screen when the command is finished (e.g., when a READY prompt is displayed), but it can be difficult for a script to do this. For such early-unlock hosts, the only option in a script is to poll the screen until it can determine that the command is complete. π
Another complication is that host I/O and script operation are asynchronous. That is, the host can update the screen at any time, even between actions that are reading the screen contents, so a script can get inconsistent results. Assistance for this problem is provided by the Snap() action. The Snap(save) action saves a snapshot of the screen in a special buffer. Then the script can use Snap() variants of the Ascii1() and Ebcdic1() actions (Snap(Ascii1) and Snap(Ebcdic1)) to query the saved buffer β which the host cannot modify β to get the data it wants. Finally, Snap(wait,output) blocks the script until the host modifies the screen, specifically since the last call to Snap(save). Thus a script can poll the screen efficiently by writing a loop that begins with Snap(save) and ends with Snap(wait,output). π
π SCRIPT-SPECIFIC ACTIONS π
The following actions have been defined or modified for use with scripts. Note that actions that use row and column coordinates generally use an origin of 1, with row 1 at the top and column 1 at the left. This is consistent with the on-screen cursor position and data stream trace messages. π―
AnsiText()
Outputs whatever data has been output by the host in NVT mode since the last time that AnsiText() was called. The data is preceded by the string "data: ", and has had all control characters expanded into C backslash sequences. π
This is a convenient way to capture NVT mode output in a synchronous manner without trying to decode the screen contents. π
Ascii1(row,col,rows,cols)
Ascii1(row,col,length)
Ascii1(length)
Ascii1()
Outputs an ASCII text representation of the screen contents. Each line is preceded by the string "data: ", and there are no control characters. β¨
If four parameters are given, a rectangular region of the screen is output. Note that the row and column are 1-origin. π
If three parameters are given, length characters are output, starting at the specified 1-origin row and column. π’
If only the length parameter is given, that many characters are output, starting at the cursor position. π
If no parameters are given, the entire screen is output. π₯οΈ
The EBCDIC-to-ASCII translation and output character set depend on both the emulator host code page (the -codepage option) and the locale. UTF-8 and certain DBCS locales may result in multi-byte expansions of EBCDIC characters that translate to ASCII codes greater than 0x7f. π
AsciiField()
Outputs an ASCII text representation of the field containing the cursor. The text is preceded by the string "data: ". π
Connect(hostname)
Connects to a host. The command does not return until the emulator is successfully connected in the proper mode, or the connection fails. π
CloseScript(status)β tells the emulator to stop reading commands from the script, bestie π . This is lowkey iconic for letting a peer script exit while the emulator keeps going interactively. (Without this, the emulator would just exit the moment it detected end-of-file on standard input. Rude.) If the script was invoked by theScript()action, the optional status becomes the return status ofScript()β and if it's nonzero,Script()completes with an error, and if this script was invoked as part of login through theibm_hostsfile, the connection gets broken. So likeβ¦ use with intention β¨Disconnect()β disconnects from the host. That's it, that's the whole vibe π¦Ebcdic1(row,col,rows,cols)Ebcdic1(row,col,length)Ebcdic1(length)Ebcdic1()β same function asAscii1()above, except instead of generating ASCII text, each character is output as a 2-digit or 4-digit hexadecimal EBCDIC code π₯EbcdicField()β same function asAsciiField()above, except it generates hexadecimal EBCDIC codes πInfo(message)β inx3270, pops up an informational message. Inc3270andwc3270, writes an informational message to the OIA (that's the line below the display, iykyk). Not defined fors3270ortcl3270πExpect(text[,timeout])β pauses the script until the specified text shows up in the data stream from the host, or until the specified timeout (in seconds) expires β³. If you don't give a timeout, the default is 30 seconds. Text can contain standard C-language escape (backslash) sequences. No wild-card characters or pattern anchor characters are understood β like, none, don't try it. And heads up:Expect()is valid only in NVT mode π«ΆMoveCursor1(row,col)β moves the cursor to the specified 1-origin coordinates β¨MoveCursor1(offset)β moves the cursor to the specified offset. Offset 0 is the upper left-hand corner of the screen π―PrintText([command,]filter)β pipes an ASCII representation of the current screen image through the named filter, e.g.,lprπ¨οΈPrintText([html,][append,][replace,]file,filename)β saves the current screen contents in a file. With thehtmloption it saves it as HTML, otherwise as plain ASCII. Theappendoption (which is the default, fyi) causes the data to be appended to the file if it already exists. Thereplaceoption causes the file to be overwritten instead πΎPrintText(html,string)β returns the current screen contents as HTML πQuery(keyword)β returns state information. The keywords are:BindPluNameβ BIND PLU returned by the hostConnectionStateβ TN3270/TN3270E mode and submodeCodePageβ Host code pageCursorβ Cursor position (row col) zero-originCursor1β Cursor position (row col) 1-originFormattedβ 3270 format state (formatted or unformatted)Hostβ Host name and portLocalEncodingβ Local character encodingLuNameβ Host name LU nameModelβ 3270 model name (IBM-327x-n)ScreenCurSizeβ Current screen size (rows cols)ScreenMaxSizeβ Maximum screen size (rows cols)Tlsβ TLS state (secureornot-secure) and host validation state (host-verifiedorhost-unverified)
Without a keyword, Query() returns each of the defined attributes, one per line, labeled by its name π·οΈ
ReadBuffer(ascii)β dumps the contents of the screen buffer, one line per row π. Each buffer position inside a data field is generally output as a 2-digit hexadecimal code, translated from the host EBCDIC code page to the current locale. (E.g., the EBCDIC value for the letter A in host code page 037 isX'C1'. In ASCII, this is0x41, so it is output as41.) If the current locale specifies a multi-byte character set such as UTF-8, some positions may be output as 4-, 6- or 8-digit codes. (E.g., in host code page 037, the EBCDIC value for a U+00ac NOT symbol isX'5F'. In UTF-8, this is0xc2, 0xac, so it is output asc2ac.) DBCS characters take two positions in the screen buffer; the first location is output as a multi-byte code, and the second location is output as a dash. Start-of-field characters (each of which takes up a display position) are output asSF(aa=nn[,...]), where aa is a field attribute type and nn is its value:c0basic 3270 β20protected,10numeric,04detectable,08intensified,0cnon-display,01modified41highlighting βf1blink,f2reverse,f4underscore,f8intensify42foreground βf0neutral black,f1blue,f2red,f3pink,f4green,f5turquoise,f6yellow,f7neutral white,f8black,f9deep blue,faorange,fbpurple,fcpale green,fdpale turquoise,fegrey,ffwhite43character set βf0default,f1APL,f8DBCS
Extended attributes (which do not take up display positions) are output as SA(aa=nn), with aa and nn having the same definitions as above (though the basic 3270 attribute will never appear as an extended attribute).
NULL characters in the screen buffer are reported as ASCII character 00 instead of 20, even though they are displayed as blanks π
ReadBuffer(ebcdic)β equivalent toReadBuffer(ascii), but with the data fields output as hexadecimal EBCDIC codes. If a buffer position has the Graphic Escape attribute, it is displayed asGE(xx). If a buffer position was written in NVT mode, it does not have an EBCDIC value, and will be displayed as00πReadBuffer(unicode)β equivalent toReadBuffer(ascii), but with the data fields output as 4-digit hexadecimal Unicode values βReadBuffer(field)β dumps information about the current field. Theascii,ebcdicandunicodekeywords are also accepted. The output consists of keywords and parameters. Note thatfield startis the location of the start-of-field character, which is displayed on the screen as a blank to the left of the field, and is dumped asSF. TheContentsline is always last π§Start1β row col β Field start coordinates (1-origin)StartOffsetβ offset β Field start location as offsetCursor1β row col β Cursor coordinates (1-origin)CursorOffsetβ offset β Cursor location as offsetContentsβ contents β Field contents on one line inReadBuffer()format
Script(path[,arg...])β runs a child script, passing it optional command-line arguments. path must specify an executable (binary) program: the emulator will create a new process and execute it. If you simply want the emulator to read commands from a file, use theSource()action instead π«‘Snap()β equivalent toSnap(save)(see below) πΈSnap(Ascii1,...)β performs theAscii1action on the saved screen image β¨Snap(Cols)β returns the number of columns in the saved screen image πSnap(Ebcdic1,...)β performs theEbcdic1()action on the saved screen image πSnap(ReadBuffer)β performs theReadBuffer()action on the saved screen image πSnap(Rows)β returns the number of rows in the saved screen image πSnap(save)β saves a copy of the screen image and status in a temporary buffer. This copy can be queried with otherSnap()actions so a script can examine a consistent screen image, even when the host may be changing the image (or even the screen dimensions) dynamically. Honestly? Chef's kiss consistency πSnap(status)β returns the status line from when the screen was last saved π·οΈSnap(wait[,timeout],output)β pauses the script until the host sends further output, then updates the snap buffer with the new screen contents. Used when the host unlocks the keyboard (allowing the script to proceed after anEnter(),PF()orPA()action), but has not finished updating the screen. This action is usually invoked in a loop that uses theSnap(Ascii1)orSnap(Ebcdic1)action to scan the screen for some pattern that indicates that the host has fully processed the last command π
Quick Snap() timeout tea: the optional timeout parameter is a number of seconds to wait before failing the Snap() action. Default? Wait indefinitely, bestie. β³π
Source(file)β Reads and executes commands from file. Any output from those commands becomes the output fromSource(). If any of the commands fails,Source()will not abort β it keeps reading commands until EOF. π«ΆTitle(text)β Changes the x3270 window title to text. Main character energy for your window bar. β¨Transfer(keyword=value,...)β Invokes IND$FILE file transfer. See FILE TRANSFER below. π¦Wait([timeout,] 3270mode)β For hosts that switch between NVT mode and 3270 mode. Pauses the script or macro until the host negotiates 3270 mode, then waits for a formatted screen as above. The optionaltimeoutparameter is a number of seconds to wait before failing theWait()action. Default: wait indefinitely. For backwards compatibility,Wait(3270)is equivalent toWait(3270mode). π¦Wait([timeout,] disconnect)β Pauses the script until the host disconnects. Often used after sending a logoff command to a VM/CMS host, to ensure that the session is not unintentionally set to disconnected state. The optionaltimeoutparameter is a number of seconds to wait before failing theWait()action. Default: wait indefinitely. πWait([timeout,] inputfield)β A useful utility for use at the beginning of scripts and after theConnect()action. In 3270 mode, waits until the screen is formatted and the host has positioned the cursor on a modifiable field. In NVT mode, waits until the host sends at least one byte of data. The optionaltimeoutparameter is a number of seconds to wait before failing theWait()action. Default: wait indefinitely. For backwards compatibility,Waitis equivalent toWait(inputfield). πWait([timeout,] nvtmode)β For hosts that switch between 3270 mode and NVT mode. Pauses the script or macro until the host negotiates NVT mode, then waits for a byte from the host as above. The optionaltimeoutparameter is a number of seconds to wait before failing theWait()action. Default: wait indefinitely. For backwards compatibility,Wait(ansi)is equivalent toWait(nvtmode). πWait([timeout,] output)β Pauses the script until the host sends further output. Often needed when the host unlocks the keyboard (allowing the script to proceed after aClear(),Enter(),PF()orPA()action), but has not finished updating the screen. Also used in non-blocking AID mode (see DIFFERENCES for details). This action is usually invoked in a loop that uses theAscii1()orEbcdic1()action to scan the screen for some pattern that indicates that the host has fully processed the last command. The optionaltimeoutparameter is a number of seconds to wait before failing theWait()action. Default: wait indefinitely. πWait([timeout,] unlock)β Pauses the script until the host unlocks the keyboard. This is useful when operating in non-blocking AID mode (toggleAidWaitclear), to wait for a host command to complete. See DIFFERENCES for details. The optionaltimeoutparameter is a number of seconds to wait before failing theWait()action. Default: wait indefinitely. πWait(timeout, seconds)β Delays the script timeout seconds. Unlike the other forms ofWait(), thetimeoutis not optional. β°WindowState(mode)β If mode isiconic, changes the x3270 window into an icon. If mode isnormal, changes the x3270 window from an icon to a normal window. πͺ
π₯ FILE TRANSFER π₯
The Transfer() action implements IND$FILE file transfer. This action requires that the IND$FILE program be installed on the IBM host, and that the 3270 cursor be located in a field that will accept a TSO or VM/CMS command. π€
Because of the complexity and number of options for file transfer, the parameters to the Transfer() action can take the unique form of option=value. They can also be given with their parameters separately. Options can appear in any order. Note that if the value contains spaces (such as a VM/CMS file name), then the entire parameter must be quoted, e.g., "hostfile=xxx foo a". With sequential options, this would be hostfile,"xxx foo a". The options are: π
directionβ Required? No. Default:receive. Other values:send.hostfileβ Required? Yes.localfileβ Required? Yes.hostβ Required? No. Default:tso. Other values:vm,cics.modeβ Required? No. Default:ascii. Other values:binary.crβ Required? No. Default:remove. Other values:add,keep.remapβ Required? No. Default:yes. Other values:no.existβ Required? No. Default:keep. Other values:replace,append.recfmβ Required? No. Other values:fixed,variable,undefined.lreclβ Required? No.blksizeβ Required? No.allocationβ Required? No. Other values:tracks,cylinders,avblock.primaryspaceβ Required? Sometimes.secondaryspaceβ Required? No.avblockβ Required? Sometimes.buffersizeβ Required? No. Default:4096.
The option details are as follows. π§
directionβsendto send a file to the host,receiveto receive a file from the host.hostfileβ The name of the file on the host.localfileβ The name of the file on the local workstation.hostβ The type of host (which dictates the form of the IND$FILE command):tso(the default),vmorcics.modeβ Useascii(the default) for a text file, which will be translated between EBCDIC and ASCII as necessary. Usebinaryfor non-text files.crβ Controls how newline characters are handled when transferringmode=asciifiles.remove(the default) strips newline characters in local files before transferring them to the host.addadds newline characters to each host file record before transferring it to the local workstation.keeppreserves newline characters when transferring a local file to the host.remapβ Controls text translation formode=asciifiles. The valueyes(the default) causes s3270 to remap the text to ensure maximum compatibility between the workstationβs character set and encoding and the hostβs EBCDIC code page. The valuenocauses s3270 to pass the text to or from the host as-is, leaving all translation to theIND$FILEprogram on the host.existβ Controls what happens when the destination file already exists.keep(the default) preserves the file, causing theTransfer()action to fail.replaceoverwrites the destination file with the source file.appendappends the source file to the destination file.recfmβ Controls the record format of files created on the host. (TSO and VM hosts only.)fixedcreates a file with fixed-length records.variablecreates a file with variable-length records.undefinedcreates a file with undefined-length records (TSO hosts only). Thelrecloption controls the record length or maximum record length forrecfm=fixedandrecfm=variablefiles, respectively.lreclβ Specifies the record length (or maximum record length) for files created on the host. (TSO and VM hosts only.)blksizeβ Specifies the block size for files created on the host. (TSO and VM hosts only.)allocationβ Specifies the units for theprimaryspaceandsecondaryspaceoptions:tracks,cylindersoravblock. (TSO hosts only.)primaryspaceβ Primary allocation for a file. The units are given by theallocationoption. Required when the allocation is specified as something other than default. (TSO hosts only.)secondaryspaceβ Secondary allocation for a file. The units are given by theallocationoption. (TSO hosts only.)avblockβ Average block size, required whenallocationspecifiesavblock. (TSO hosts only.)buffersizeβ Buffer size for DFT-mode transfers. Can range from256to32768. Larger values give better performance, but some hosts may not be able to support them. π
There are also resources that control the default values for each of the file transfer parameters. These resources have the same names as the Transfer() keywords, but with ft prepended and the option name capitalized. E.g., the default for the mode keyword is the s3270.ftMode resource. π
π DEPRECATED/COMPATIBILITY ACTIONS π
For compatibility with earlier versions, there are alternate versions of several of these actions. These versions use zero-origin coordinates, with row 0 at the top and column 0 on the left. π
Ascii(...)Ebcdic(...)MoveCursor(...)β Identical toAscii1(),Ebcdic1()andMoveCursor1(), but using zero-origin coordinates.
The Snap() action also accepts Ascii and Ebcdic keywords, allowing zero-origin coordinates. π«Ά
πΈ SEE ALSO πΈ
β VERSION β
Version 4.0ga14
Thatβs the whole X3270-SCRIPT(1) vibe β source/version Version 4.0ga14, dated 31 January 2021. Byeeee, bestie ππ¦
π¦ where this page comes from
- centos-stream 9: x3270 4.0ga14-2.el9 Β· BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms