1X3270-SCRIPT(1) General Commands Manual X3270-SCRIPT(1)
2
3
4
6 Scripting Facilities for x3270, c3270 and s3270
7
9 x3270 -script [ x3270-options ]
10 x3270 -socket [ x3270-options ]
11 x3270 -scriptport port [ x3270-options ]
12 c3270 -socket [ c3270-options ]
13 c3270 -scriptport port [ s3270-options ]
14 s3270 [ s3270-options ]
15 Script ( command [ ,arg... ] )
16
18 The x3270 scripting facilities allow the interactive 3270 emulators
19 x3270 and c3270 to be operated under the control of another program,
20 and forms the basis for the script-only emulator s3270.
21
22 There are four basic scripting methods. The first is the peer script
23 facility, invoked by the x3270 -script switch, and the default mode for
24 s3270. This runs the emulator as a child of another process. Typi‐
25 cally this would be a script using expect(1), perl(1), or the co-
26 process facility of the Korn Shell ksh(1). In this mode, the emulator
27 process looks for commands on its standard input, and places the
28 responses on standard output.
29
30 The second method is the child script facility, invoked by the emula‐
31 tor's Script action. This runs a script as a child process of the emu‐
32 lator. The child has access to pipes connected to the emulator; the
33 emulator looks for commands on one pipe, and places the responses on
34 the other. The file descriptor of the pipe for commands to the emula‐
35 tor is passed in the environment variable X3270INPUT (e.g., the text
36 string "7" if the file descriptor is 7); the file descriptor of the
37 pipe for responses from the emulator is passed in the environment vari‐
38 able X3270OUTPUT.
39
40 The third method uses a TCP socket. The -scrpiptport command-line
41 option causes the emulator to bind a socket to the specified port (on
42 the IPv4 loopback address, 127.0.0.1). The emulator accepts TCP con‐
43 nections on that port. Multiple commands and responses can be sent
44 over each connection.
45
46 The fourth method uses a Unix-domain socket. The -socket command-line
47 option causes the emulator to create a Unix-domain stream socket named
48 /tmp/x3sck.pid. The emulator accepts connections to that socket. Mul‐
49 tiple commands and responses can be sent over each connection.
50
51 It is possible to nest the methods. For example, a peer or TCP socket
52 script can invoke the Script action. The calling script will be
53 resumed when the nested script completes.
54
55 Commands are emulator actions; the syntax is the same as for the right-
56 hand side of an x3270 or c3270 keymap. Unlike translation tables,
57 action names are case-insensitive, can be uniquely abbreviated, and the
58 parentheses may be omitted if there are no parameters. Any input line
59 that begins with # or ! is treaded as a comment and will be ignored.
60
61 Any emulator action may be specified. Several specific actions have
62 been defined for use by scripts, and the behavior of certain other
63 actions (and of the emulators in general) is different when an action
64 is initiated by a script.
65
66 Some actions generate output; some may delay completion until the cer‐
67 tain external events occur, such as the host unlocking the keyboard.
68 The completion of every command is marked by a two-line message. The
69 first line is the current status of the emulator, documented below. If
70 the command is successful, the second line is the string "ok"; other‐
71 wise it is the string "error".
72
74 The status message consists of 12 blank-separated fields:
75
76 1 Keyboard State
77 If the keyboard is unlocked, the letter U. If the keyboard is
78 locked waiting for a response from the host, or if not connected
79 to a host, the letter L. If the keyboard is locked because of
80 an operator error (field overflow, protected field, etc.), the
81 letter E.
82
83 2 Screen Formatting
84 If the screen is formatted, the letter F. If unformatted or in
85 NVT mode, the letter U.
86
87 3 Field Protection
88 If the field containing the cursor is protected, the letter P.
89 If unprotected or unformatted, the letter U.
90
91 4 Connection State
92 If connected to a host, the string C(hostname). Otherwise, the
93 letter N.
94
95 5 Emulator Mode
96 If connected in 3270 mode, the letter I. If connected in NVT
97 line mode, the letter L. If connected in NVT character mode,
98 the letter C. If connected in unnegotiated mode (no BIND active
99 from the host), the letter P. If not connected, the letter N.
100
101 6 Model Number (2-5)
102
103 7 Number of Rows
104 The current number of rows defined on the screen. The host can
105 request that the emulator use a 24x80 screen, so this number may
106 be smaller than the maximum number of rows possible with the
107 current model.
108
109 8 Number of Columns
110 The current number of columns defined on the screen, subject to
111 the same difference for rows, above.
112
113 9 Cursor Row
114 The current cursor row (zero-origin).
115
116 10 Cursor Column
117 The current cursor column (zero-origin).
118
119 11 Window ID
120 The X window identifier for the main x3270 window, in hexadeci‐
121 mal preceded by 0x. For s3270 and c3270, this is zero.
122
123 12 Command Execution Time
124 The time that it took for the host to respond to the previous
125 commnd, in seconds with milliseconds after the decimal. If the
126 previous command did not require a host response, this is a
127 dash.
128
130 When an action is initiated by a script, the emulators behave in sev‐
131 eral different ways:
132
133 If an error occurs in processing an action, the usual pop-up window
134 does not appear. Instead, the text is written to standard output.
135
136 If end-of-file is detected on standard input, the emulator exits. (A
137 script can exit without killing the emulator by using the CloseScript
138 action, below.) Note that this applies to peer scripts only; end-of-
139 file on the pipe connected to a child script simply causes the pipes to
140 be closed and the Script action to complete.
141
142 The Quit action always causes the emulator to exit. (When called from
143 the keyboard, it will exit only if not connected to a host.)
144
145 Normally, the AID actions (Clear, Enter, PF, and PA) will not complete
146 until the host unlocks the keyboard. If the parameter to a String
147 action includes a code for one these actions, it will also wait for the
148 keyboard to unlock before proceeding.
149
150 The AidWait toggle controls with behavior. When this toggle is set
151 (the default), actions block as described above. When the toggle is
152 clear, AID actions complete immediately. The Wait(Output) action can
153 then be used to delay a script until the host changes something on the
154 screen, and the Wait(Unlock) action can be used to delay a script until
155 the host unlocks the keyboard, regardless of the state of the AidWait
156 toggle.
157
158 Note that the Script action does not complete until end-of-file is
159 detected on the pipe or the CloseScript action is called by the child
160 process. This behavior is not affected by the state of the AidWait
161 toggle.
162
164 3270 session scripting can be more difficult than other kinds of
165 scripting, because it can be hard to tell when the host is finished
166 processing a command. There is a well-defined 3270 Data Stream facil‐
167 ity for doing this: The emulator locks the keyboard when it sends the
168 host an AID, and the later host unlocks the keyboard. The emulator
169 supports this facility directly by not allowing an AID action to com‐
170 plete until the keyboard is unlocked. Unfortunately, some hosts and
171 some host applications unlock the keyboard as soon as they begin pro‐
172 cessing the command, instead of after it is finished. A human operator
173 can see on the screen when the command is finished (e.g., when a READY
174 prompt is displayed), but it can be difficult for a script to do this.
175 For such early-unlock hosts, the only option in a script is to poll the
176 screen until it can determine that the command is complete.
177
178 Another complication is that host I/O and script operation are asyn‐
179 chronous. That is, the host can update the screen at any time, even
180 between actions that are reading the screen contents, so a script can
181 get inconsistent results. Assistance for this problem is provided by
182 the Snap action. The Snap(Save) action saves a snapshot of the screen
183 in a special buffer. Then the script can use Snap variants of the Ascii
184 and Ebcdic actions (Snap(Ascii) and Snap(Ebcdic)) to query the saved
185 buffer -- which the host cannot modify -- to get the data it wants.
186 Finally, Snap(Wait Output) blocks the script until the host modifies
187 the screen, specifically since the last call to Snap(Save). Thus a
188 script can poll the screen efficiently by writing a loop that begins
189 with Snap(Save) and ends with Snap(Wait Output).
190
192 The following actions have been defined or modified for use with
193 scripts. (Note that unlike the display on the status line, row and col
194 coordinates used in these actions use [0,0] as their origin at the
195 upper left, not [1,1]).
196
197 AnsiText
198 Outputs whatever data that has been output by the host in NVT
199 mode since the last time that AnsiText was called. The data is
200 preceded by the string "data: ", and has had all control charac‐
201 ters expanded into C backslash sequences.
202
203 This is a convenient way to capture NVT mode output in a syn‐
204 chronous manner without trying to decode the screen contents.
205
206 Ascii(row,col,rows,cols)
207
208 Ascii(row,col,length)
209
210 Ascii(length)
211
212 Ascii Outputs an ASCII text representation of the screen contents.
213 Each line is preceded by the string "data: ", and there are no
214 control characters.
215
216 If four parameters are given, a rectangular region of the screen
217 is output. (Note that the row and column are zero-origin.)
218
219 If three parameters are given, length characters are output,
220 starting at the specified zero-origin row and column.
221
222 If only the length parameter is given, that many characters are
223 output, starting at the cursor position.
224
225 If no parameters are given, the entire screen is output.
226
227 The EBCDIC-to-ASCII translation and output character set depend
228 on the both the emulator character set (the -charset option) and
229 the locale. UTF-8 and certain DBCS locales may result in multi-
230 byte expansions of EBCDIC characters that translate to ASCII
231 codes greater than 0x7f.
232
233 AsciiField
234 Outputs an ASCII text representation of the field containing the
235 cursor. The text is preceded by the string "data: ".
236
237 Connect(hostname)
238 Connects to a host. The command does not return until the emu‐
239 lator is successfully connected in the proper mode, or the con‐
240 nection fails.
241
242 CloseScript(status)
243 Causes the emulator to stop reading commands from the script.
244 This is useful to allow a peer script to exit, with the emulator
245 proceeding interactively. (Without this command, the emulator
246 would exit when it detected end-of-file on standard input.) If
247 the script was invoked by the Script action, the optional status
248 is used as the return status of Script; if nonzero, Script will
249 complete with an error, and if this script was invoked as part
250 of login through the ibm_hosts file, the connection will be bro‐
251 ken.
252
253 ContinueScript([param])
254 Allows a script that is waiting in a PauseScript action, below,
255 to continue. The optional param string is output by the Paus‐
256 eScript action.
257
258 Disconnect
259 Disconnects from the host.
260
261 Ebcdic(row,col,rows,cols)
262
263 Ebcdic(row,col,length)
264
265 Ebcdic(length)
266
267 Ebcdic The same function as Ascii above, except that rather than gener‐
268 ating ASCII text, each character is output as a 2-digit or
269 4-digit hexadecimal EBCDIC code.
270
271 EbcdicField
272 The same function as AsciiField above, except that it generates
273 hexadecimal EBCDIC codes.
274
275 Info(message)
276 In x3270, pops up an informational message. In c3270 and
277 wc3270, writes an informational message to the OIA (the line
278 below the display). Not defined for s3270 or tcl3270.
279
280 Expect(text[,timeout])
281 Pauses the script until the specified text appears in the data
282 stream from the host, or the specified timeout (in seconds)
283 expires. If no timeout is specified, the default is 30 seconds.
284 Text can contain standard C-language escape (backslash)
285 sequences. No wild-card characters or pattern anchor characters
286 are understood. Expect is valid only in NVT mode.
287
288 MoveCursor(row,col)
289 Moves the cursor to the specified zero-origin coordinates.
290
291 PauseScript
292 Stops a script until the ContinueScript action, above, is exe‐
293 cuted. This allows a script to wait for user input and con‐
294 tinue. Outputs the single parameter to ContinueScript, if one
295 is given.
296
297 PrintText([command,]filter)
298 Pipes an ASCII representation of the current screen image
299 through the named filter, e.g., lpr.
300
301 PrintText([html,][append,][replace,]file,filename)
302 Saves the current screen contents in a file. With the html
303 option, saves it as HTML, otherwise saves it as plain ASCII.
304 The append option (the default) causes the data to be appended
305 to the file if it already exists. The replace option causes the
306 file to be overwritten instead.
307
308 PrintText(html,string)
309 Returns the current screen contents as HTML.
310
311 Query(keyword)
312 Returns state information. Keywords are:
313
314 Keyword Output
315 ─────────────────────────────────────────────
316 BindPluName BIND PLU returned by the
317 host
318 ConnectionState TN3270/TN3270E mode and
319 submode
320 CodePage Host code page
321 Cursor Cursor position (row col)
322 Formatted 3270 format state
323 (formatted or unformatted)
324 Host Host name and port
325 LocalEncoding Local character encoding
326 LuName Host name LU name
327 Model 3270 model name (IBM-327x-
328 n)
329 ScreenCurSize Current screen size (rows
330 cols)
331 ScreenMaxSize Maximum screen size (rows
332 cols)
333
334
335
336
337
338 Ssl SSL state (secure or not-
339 secure) and host
340 validation state (host-
341 verified or host-
342 unverified)
343
344 Without a keyword, Query returns each of the defined attributes,
345 one per line, labeled by its name.
346
347 ReadBuffer(Ascii)
348 Dumps the contents of the screen buffer, one line at a time.
349 Positions inside data fields are generally output as 2-digit
350 hexadecimal codes in the current display character set. If the
351 current locale specifies UTF-8 (or certain DBCS character sets),
352 some positions may be output as multi-byte strings (4-, 6- or
353 8-digit codes). DBCS characters take two positions in the
354 screen buffer; the first location is output as a multi-byte
355 string in the current locale codeset, and the second location is
356 output as a dash. Start-of-field characters (each of which
357 takes up a display position) are output as SF(aa=nn[,...]),
358 where aa is a field attribute type and nn is its value.
359
360 Attribute Values
361 ─────────────────────────────────────
362 c0 basic 3270 20 protected
363 10 numeric
364 04 detectable
365 08 intensified
366 0c non-display
367 01 modified
368 41 highlighting f1 blink
369 f2 reverse
370 f4 underscore
371 f8 intensify
372 42 foreground f0 neutral black
373 f1 blue
374 f2 red
375 f3 pink
376 f4 green
377 f5 turquoise
378 f6 yellow
379 f7 neutral white
380 f8 black
381 f9 deep blue
382 fa orange
383 fb purple
384 fc pale green
385 fd pale turquoise
386 fe grey
387 ff white
388 43 character set f0 default
389 f1 APL
390 f8 DBCS
391
392 Extended attributes (which do not take up display positions) are
393 output as SA(aa=nn), with aa and nn having the same definitions
394 as above (though the basic 3270 attribute will never appear as
395 an extended attribute).
396
397 In addition, NULL characters in the screen buffer are reported
398 as ASCII character 00 instead of 20, even though they should be
399 displayed as blanks.
400
401 ReadBuffer(Ebcdic)
402 Equivalent to ReadBuffer(Ascii), but with the data fields output
403 as hexadecimal EBCDIC codes instead. Additionally, if a buffer
404 position has the Graphic Escape attribute, it is displayed as
405 GE(xx).
406
407 Script(path[,arg...])
408 Runs a child script, passing it optional command-line arguments.
409 path must specify an executable (binary) program: the emulator
410 will create a new process and execute it. If you simply want the
411 emulator to read commands from a file, use the Source action.
412
413 Snap Equivalent to Snap(Save) (see below).
414
415 Snap(Ascii,...)
416 Performs the Ascii action on the saved screen image.
417
418 Snap(Cols)
419 Returns the number of columns in the saved screen image.
420
421 Snap(Ebcdic,...)
422 Performs the Ebcdic action on the saved screen image.
423
424 Snap(ReadBuffer)
425 Performs the ReadBuffer action on the saved screen image.
426
427 Snap(Rows)
428 Returns the number of rows in the saved screen image.
429
430 Snap(Save)
431 Saves a copy of the screen image and status in a temporary
432 buffer. This copy can be queried with other Snap actions to
433 allow a script to examine a consistent screen image, even when
434 the host may be changing the image (or even the screen
435 dimensions) dynamically.
436
437 Snap(Status)
438 Returns the status line from when the screen was last saved.
439
440 Snap(Wait[,timeout],Output)
441 Pauses the script until the host sends further output, then
442 updates the snap buffer with the new screen contents. Used when
443 the host unlocks the keyboard (allowing the script to proceed
444 after an Enter, PF or PA action), but has not finished updating
445 the screen. This action is usually invoked in a loop that uses
446 the Snap(Ascii) or Snap(Ebcdic) action to scan the screen for
447 some pattern that indicates that the host has fully processed
448 the last command.
449
450 The optional timeout parameter specifies a number of seconds to
451 wait before failing the Snap action. The default is to wait
452 indefinitely.
453
454 Source(file)
455 Read and execute commands from file. Any output from those
456 commands will become the output from Source. If any of the
457 commands fails, the Source command will not abort; it will
458 continue reading commands until EOF.
459
460 Title(text)
461 Changes the x3270 window title to text.
462
463 Transfer(keyword=value,...)
464 Invokes IND$FILE file transfer. See FILE TRANSFER below.
465
466 Wait([timeout,] 3270Mode)
467 Used when communicating with a host that switches between NVT
468 mode and 3270 mode. Pauses the script or macro until the host
469 negotiates 3270 mode, then waits for a formatted screen as
470 above.
471
472 The optional timeout parameter specifies a number of seconds to
473 wait before failing the Wait action. The default is to wait
474 indefinitely.
475
476 For backwards compatibility, Wait(3270) is equivalent to
477 Wait(3270Mode)
478
479 Wait([timeout,] Disconnect)
480 Pauses the script until the host disconnects. Often used to
481 after sending a logoff command to a VM/CMS host, to ensure that
482 the session is not unintentionally set to disconnected state.
483
484 The optional timeout parameter specifies a number of seconds to
485 wait before failing the Wait action. The default is to wait
486 indefinitely.
487
488 Wait([timeout,] InputField)
489 A useful utility for use at the beginning of scripts and after
490 the Connect action. In 3270 mode, waits until the screen is
491 formatted, and the host has positioned the cursor on a
492 modifiable field. In NVT mode, waits until the host sends at
493 least one byte of data.
494
495 The optional timeout parameter specifies a number of seconds to
496 wait before failing the Wait action. The default is to wait
497 indefinitely.
498
499 For backwards compatibility, Wait is equivalent to
500 Wait(InputField).
501
502 Wait([timeout,] NVTMode)
503 Used when communicating with a host that switches between 3270
504 mode and NVT mode. Pauses the script or macro until the host
505 negotiates NVT mode, then waits for a byte from the host as
506 above.
507
508 The optional timeout parameter specifies a number of seconds to
509 wait before failing the Wait action. The default is to wait
510 indefinitely.
511
512 For backwards compatibility, Wait(ansi) is equivalent to
513 Wait(NVTMode).
514
515 Wait([timeout,] Output)
516 Pauses the script until the host sends further output. Often
517 needed when the host unlocks the keyboard (allowing the script
518 to proceed after a Clear, Enter, PF or PA action), but has not
519 finished updating the screen. Also used in non-blocking AID
520 mode (see DIFFERENCES for details). This action is usually
521 invoked in a loop that uses the Ascii or Ebcdic action to scan
522 the screen for some pattern that indicates that the host has
523 fully processed the last command.
524
525 The optional timeout parameter specifies a number of seconds to
526 wait before failing the Wait action. The default is to wait
527 indefinitely.
528
529 Wait([timeout,] Unlock)
530 Pauses the script until the host unlocks the keyboard. This is
531 useful when operating in non-blocking AID mode (toggle AidWait
532 clear), to wait for a host command to complete. See DIFFERENCES
533 for details).
534
535 The optional timeout parameter specifies a number of seconds to
536 wait before failing the Wait action. The default is to wait
537 indefinitely.
538
539 Wait(timeout, Seconds)
540 Delays the script timeout seconds. Unlike the other forms of
541 Wait, the timeout is not optional.
542
543 WindowState(mode)
544 If mode is Iconic, changes the x3270 window into an icon. If
545 mode is Normal, changes the x3270 window from an icon to a
546 normal window.
547
549 The Transfer action implements IND$FILE file transfer. This action
550 requires that the IND$FILE program be installed on the IBM host, and
551 that the 3270 cursor be located in a field that will accept a TSO or
552 VM/CMS command.
553
554 Because of the complexity and number of options for file transfer, the
555 parameters to the Transfer action take the unique form of option=value,
556 and can appear in any order. Note that if the value contains spaces
557 (such as a VM/CMS file name), then the entire parameter must be quoted,
558 e.g., "HostFile=xxx foo a". The options are:
559
560 Option Required? Default Other Values
561 ────────────────────────────────────────────────────────
562 Direction No receive send
563 HostFile Yes
564 LocalFile Yes
565 Host No tso vm, cics
566 Mode No ascii binary
567 Cr No remove add, keep
568 Remap No yes no
569 Exist No keep replace, append
570 Recfm No fixed, variable,
571 undefined
572 Lrecl No
573 Blksize No
574 Allocation No tracks,
575 cylinders,
576 avblock
577 PrimarySpace Sometimes
578 SecondarySpace No
579 Avblock Sometimes
580 BufferSize No 4096
581
582 The option details are as follows.
583
584 Direction
585 send to send a file to the host, receive to receive a file from
586 the host.
587
588 HostFile
589 The name of the file on the host.
590
591 LocalFile
592 The name of the file on the local workstation.
593
594 Host The type of host (which dictates the form of the IND$FILE
595 command): tso (the default), vm or cics.
596
597 Mode Use ascii (the default) for a text file, which will be
598 translated between EBCDIC and ASCII as necessary. Use binary
599 for non-text files.
600
601 Cr Controls how Newline characters are handled when transferring
602 Mode=ascii files. remove (the default) strips Newline
603 characters in local files before transferring them to the host.
604 add adds Newline characters to each host file record before
605 transferring it to the local workstation. keep preserves
606 Newline characters when transferring a local file to the host.
607
608 Remap Controls text translation for Mode=ascii files. The value yes
609 (the default) causes s3270 to remap the text to ensure maximum
610 compatibility between the workstation's character set and
611 encoding and the host's EBCDIC code page. The value no causes
612 s3270 to pass the text to or from the host as-is, leaving all
613 translation to the IND$FILE program on the host.
614
615 Exist Controls what happens when the destination file already exists.
616 keep (the default) preserves the file, causing the Transfer
617 action to fail. replace overwrites the destination file with
618 the source file. append appends the source file to the
619 destination file.
620
621 Recfm Controls the record format of files created on the host. (TSO
622 and VM hosts only.) fixed creates a file with fixed-length
623 records. variable creates a file with variable-length records.
624 undefined creates a file with undefined-length records (TSO
625 hosts only). The Lrecl option controls the record length or
626 maximum record length for Recfm=fixed and Recfm=variable files,
627 respectively.
628
629 Lrecl Specifies the record length (or maximum record length) for files
630 created on the host. (TSO and VM hosts only.)
631
632 Blksize
633 Specifies the block size for files created on the host. (TSO
634 and VM hosts only.)
635
636 Allocation
637 Specifies the units for the PrimarySpace and SecondarySpace
638 options: tracks, cylinders or avblock. (TSO hosts only.)
639
640 PrimarySpace
641 Primary allocation for a file. The units are given by the
642 Allocation option. Required when the Allocation is specified as
643 something other than default. (TSO hosts only.)
644
645 SecondarySpace
646 Secondary allocation for a file. The units are given by the
647 Allocation option. (TSO hosts only.)
648
649 Avblock
650 Average block size, required when Allocation specifies avblock.
651 (TSO hosts only.)
652
653 BufferSize
654 Buffer size for DFT-mode transfers. Can range from 256 to
655 32768. Larger values give better performance, but some hosts
656 may not be able to support them.
657
658 There are also resources that control the default values for each of
659 the file transfer parameters. These resources have the same names as
660 the Transfer keywords, but with ft prepended. E.g., the default for the
661 Mode keyword is the s3270.ftMode resource.
662
664 expect(1)
665 perl(1)
666 ksh(1)
667 x3270(1)
668 x3270if(1)
669 c3270(1)
670 s3270(1)
671
673 Version 3.6ga10
674
675
676
677 23 February 2020 X3270-SCRIPT(1)