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 command, 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, not
195 [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.
218
219 If three parameters are given, length characters are output,
220 starting at the specified 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 param given is output by the PauseScript
256 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 hexadecimal
269 EBCDIC code, preceded by 0x.
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 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.
295
296 PrintText([command,]filter))
297 Pipes an ASCII representation of the current screen image
298 through the named filter, e.g., lpr.
299
300 PrintText([html,][append,][replace,]file,filename))
301 Saves the current screen contents in a file. With the html
302 option, saves it as HTML, otherwise saves it as plain ASCII.
303 The append option (the default) causes the data to be appended
304 to the file if it already exists. The replace option causes the
305 file to be overwritten instead.
306
307 PrintText(html,string)
308 Returns the current screen contents as HTML.
309
310 Query(keyword)
311 Returns state information. Keywords are:
312
313 Keyword Output
314 ─────────────────────────────────────────────
315 BindPluName BIND PLU returned by the
316 host
317 ConnectionState TN3270/TN3270E mode and
318 submode
319 CodePage Host code page
320 Cursor Cursor position (row col)
321 Formatted 3270 format state
322 (formatted or unformatted)
323 Host Host name and port
324 LocalEncoding Local character encoding
325 LuName Host name LU name
326 Model 3270 model name (IBM-327x-
327 n)
328 ScreenCurSize Current screen size (rows
329 cols)
330 ScreenMaxSize Maximum screen size (rows
331 cols)
332 Ssl SSL state (secure or not-
333 secure) and host
334 validation state (host-
335 verified or host-
336 unverified)
337
338 Without a keyword, Query returns each of the defined attributes,
339 one per line, labeled by its name.
340
341 ReadBuffer(Ascii)
342 Dumps the contents of the screen buffer, one line at a time.
343 Positions inside data fields are generally output as 2-digit
344 hexadecimal codes in the current display character set. If the
345 current locale specifies UTF-8 (or certain DBCS character sets),
346 some positions may be output as multi-byte strings (4-, 6- or
347 8-digit codes). DBCS characters take two positions in the
348 screen buffer; the first location is output as a multi-byte
349 string in the current locale codeset, and the second location is
350 output as a dash. Start-of-field characters (each of which
351 takes up a display position) are output as SF(aa=nn[,...]),
352 where aa is a field attribute type and nn is its value.
353
354 Attribute Values
355 ─────────────────────────────────────
356 c0 basic 3270 20 protected
357 10 numeric
358 04 detectable
359 08 intensified
360 0c non-display
361 01 modified
362 41 highlighting f1 blink
363 f2 reverse
364 f4 underscore
365 f8 intensify
366 42 foreground f0 neutral black
367 f1 blue
368 f2 red
369 f3 pink
370 f4 green
371 f5 turquoise
372 f6 yellow
373 f7 neutral white
374 f8 black
375 f9 deep blue
376 fa orange
377 fb purple
378 fc pale green
379 fd pale turquoise
380 fe grey
381 ff white
382 43 character set f0 default
383 f1 APL
384 f8 DBCS
385
386 Extended attributes (which do not take up display positions) are
387 output as SA(aa=nn), with aa and nn having the same definitions
388 as above (though the basic 3270 attribute will never appear as
389 an extended attribute).
390
391 In addition, NULL characters in the screen buffer are reported
392 as ASCII character 00 instead of 20, even though they should be
393 displayed as blanks.
394
395 ReadBuffer(Ebcdic)
396 Equivalent to ReadBuffer(Ascii), but with the data fields output
397 as hexadecimal EBCDIC codes instead. Additionally, if a buffer
398 position has the Graphic Escape attribute, it is displayed as
399 GE(xx).
400
401 Script(path[,arg...])
402 Runs a child script, passing it optional command-line arguments.
403 path must specify an executable (binary) program: the emulator
404 will create a new process and execute it. If you simply want the
405 emulator to read commands from a file, use the Source action.
406
407 Snap Equivalent to Snap(Save) (see below).
408
409 Snap(Ascii,...)
410 Performs the Ascii action on the saved screen image.
411
412 Snap(Cols)
413 Returns the number of columns in the saved screen image.
414
415 Snap(Ebcdic,...)
416 Performs the Ebcdic action on the saved screen image.
417
418 Snap(ReadBuffer)
419 Performs the ReadBuffer action on the saved screen image.
420
421 Snap(Rows)
422 Returns the number of rows in the saved screen image.
423
424 Snap(Save)
425 Saves a copy of the screen image and status in a temporary
426 buffer. This copy can be queried with other Snap actions to
427 allow a script to examine a consistent screen image, even when
428 the host may be changing the image (or even the screen
429 dimensions) dynamically.
430
431 Snap(Status)
432 Returns the status line from when the screen was last saved.
433
434 Snap(Wait[,timeout],Output)
435 Pauses the script until the host sends further output, then
436 updates the snap buffer with the new screen contents. Used when
437 the host unlocks the keyboard (allowing the script to proceed
438 after an Enter, PF or PA action), but has not finished updating
439 the screen. This action is usually invoked in a loop that uses
440 the Snap(Ascii) or Snap(Ebcdic) action to scan the screen for
441 some pattern that indicates that the host has fully processed
442 the last command.
443
444 The optional timeout parameter specifies a number of seconds to
445 wait before failing the Snap action. The default is to wait
446 indefinitely.
447
448 Source(file)
449 Read and execute commands from file. Any output from those
450 commands will become the output from Source. If any of the
451 commands fails, the Source command will not abort; it will
452 continue reading commands until EOF.
453
454 Title(text)
455 Changes the x3270 window title to text.
456
457 Transfer(keyword=value,...)
458 Invokes IND$FILE file transfer. See FILE TRANSFER below.
459
460 Wait([timeout,] 3270Mode)
461 Used when communicating with a host that switches between NVT
462 mode and 3270 mode. Pauses the script or macro until the host
463 negotiates 3270 mode, then waits for a formatted screen as
464 above.
465
466 The optional timeout parameter specifies a number of seconds to
467 wait before failing the Wait action. The default is to wait
468 indefinitely.
469
470 For backwards compatibility, Wait(3270) is equivalent to
471 Wait(3270Mode)
472
473 Wait([timeout,] Disconnect)
474 Pauses the script until the host disconnects. Often used to
475 after sending a logoff command to a VM/CMS host, to ensure that
476 the session is not unintentionally set to disconnected state.
477
478 The optional timeout parameter specifies a number of seconds to
479 wait before failing the Wait action. The default is to wait
480 indefinitely.
481
482 Wait([timeout,] InputField)
483 A useful utility for use at the beginning of scripts and after
484 the Connect action. In 3270 mode, waits until the screen is
485 formatted, and the host has positioned the cursor on a
486 modifiable field. In NVT mode, waits until the host sends at
487 least one byte of data.
488
489 The optional timeout parameter specifies a number of seconds to
490 wait before failing the Wait action. The default is to wait
491 indefinitely.
492
493 For backwards compatibility, Wait is equivalent to
494 Wait(InputField).
495
496 Wait([timeout,] NVTMode)
497 Used when communicating with a host that switches between 3270
498 mode and NVT mode. Pauses the script or macro until the host
499 negotiates NVT mode, then waits for a byte from the host as
500 above.
501
502 The optional timeout parameter specifies a number of seconds to
503 wait before failing the Wait action. The default is to wait
504 indefinitely.
505
506 For backwards compatibility, Wait(ansi) is equivalent to
507 Wait(NVTMode).
508
509 Wait([timeout,] Output)
510 Pauses the script until the host sends further output. Often
511 needed when the host unlocks the keyboard (allowing the script
512 to proceed after a Clear, Enter, PF or PA action), but has not
513 finished updating the screen. Also used in non-blocking AID
514 mode (see DIFFERENCES for details). This action is usually
515 invoked in a loop that uses the Ascii or Ebcdic action to scan
516 the screen for some pattern that indicates that the host has
517 fully processed the last command.
518
519 The optional timeout parameter specifies a number of seconds to
520 wait before failing the Wait action. The default is to wait
521 indefinitely.
522
523 Wait([timeout,] Unlock)
524 Pauses the script until the host unlocks the keyboard. This is
525 useful when operating in non-blocking AID mode (toggle AidWait
526 clear), to wait for a host command to complete. See DIFFERENCES
527 for details).
528
529 The optional timeout parameter specifies a number of seconds to
530 wait before failing the Wait action. The default is to wait
531 indefinitely.
532
533 Wait(timeout, Seconds)
534 Delays the script timeout seconds. Unlike the other forms of
535 Wait, the timeout is not optional.
536
537 WindowState(mode)
538 If mode is Iconic, changes the x3270 window into an icon. If
539 mode is Normal, changes the x3270 window from an icon to a
540 normal window.
541
543 The Transfer action implements IND$FILE file transfer. This action
544 requires that the IND$FILE program be installed on the IBM host, and
545 that the 3270 cursor be located in a field that will accept a TSO or
546 VM/CMS command.
547
548 The Transfer action can be entered at the command prompt with no
549 parameters, which will cause it to prompt interactively for the file
550 names and options. It can also be invoked with parameters to define
551 the entire transfer.
552
553 Because of the complexity and number of options for file transfer, the
554 parameters to the Transfer action take the unique form of option=value,
555 and can appear in any order. Note that if the value contains spaces
556 (such as a VM/CMS file name), then the entire parameter must be quoted,
557 e.g., "HostFile=xxx foo a". The options are:
558
559 Option Required? Default Other Values
560 ────────────────────────────────────────────────────────
561 Direction No receive send
562 HostFile Yes
563 LocalFile Yes
564 Host No tso vm, cics
565 Mode No ascii binary
566 Cr No remove add, keep
567 Remap No yes no
568 Exist No keep replace, append
569 Recfm No fixed, variable,
570 undefined
571 Lrecl No
572 Blksize No
573 Allocation No tracks,
574 cylinders,
575 avblock
576 PrimarySpace No
577 SecondarySpace No
578 BufferSize No 4096
579
580 The option details are as follows.
581
582 Direction
583 send to send a file to the host, receive to receive a file from
584 the host.
585
586 HostFile
587 The name of the file on the host.
588
589 LocalFile
590 The name of the file on the local workstation.
591
592 Host The type of host (which dictates the form of the IND$FILE
593 command): tso (the default), vm or cics.
594
595 Mode Use ascii (the default) for a text file, which will be
596 translated between EBCDIC and ASCII as necessary. Use binary
597 for non-text files.
598
599 Cr Controls how Newline characters are handled when transferring
600 Mode=ascii files. remove (the default) strips Newline
601 characters in local files before transferring them to the host.
602 add adds Newline characters to each host file record before
603 transferring it to the local workstation. keep preserves
604 Newline characters when transferring a local file to the host.
605
606 Remap Controls text translation for Mode=ascii files. The value yes
607 (the default) causes c3270 to remap the text to ensure maximum
608 compatibility between the workstation's character set and
609 encoding and the host's EBCDIC code page. The value no causes
610 c3270 to pass the text to or from the host as-is, leaving all
611 translation to the IND$FILE program on the host.
612
613 Exist Controls what happens when the destination file already exists.
614 keep (the default) preserves the file, causing the Transfer
615 action to fail. replace overwrites the destination file with
616 the source file. append appends the source file to the
617 destination file.
618
619 Recfm Controls the record format of files created on the host. (TSO
620 and VM hosts only.) fixed creates a file with fixed-length
621 records. variable creates a file with variable-length records.
622 undefined creates a file with undefined-length records (TSO
623 hosts only). The Lrecl option controls the record length or
624 maximum record length for Recfm=fixed and Recfm=variable files,
625 respectively.
626
627 Lrecl Specifies the record length (or maximum record length) for files
628 created on the host. (TSO and VM hosts only.)
629
630 Blksize
631 Specifies the block size for files created on the host. (TSO
632 and VM hosts only.)
633
634 Allocation
635 Specifies the units for the PrimarySpace and SecondarySpace
636 options: tracks, cylinders or avblock. (TSO hosts only.)
637
638 PrimarySpace
639 Primary allocation for a file, The units are given by the
640 Allocation option. (TSO hosts only.)
641
642 SecondarySpace
643 Secondary allocation for a file. The units are given by the
644 Allocation option. (TSO hosts only.)
645
646 BufferSize
647 Buffer size for DFT-mode transfers. Can range from 256 to
648 32768. Larger values give better performance, but some hosts
649 may not be able to support them.
650
652 expect(1)
653 perl(1)
654 ksh(1)
655 x3270(1)
656 x3270if(1)
657 c3270(1)
658 s3270(1)
659
661 Version 3.3.15ga9
662
663
664
665 28 May 2015 X3270-SCRIPT(1)