Call POSIX commands from BS2000
Component: | POSIX-BC |
Functional area: | POSIX administration and application |
Domain: | PROCEDURE |
Privileges: | STD-PROCESSING |
Function
The EXECUTE-POSIX-CMD command enables the user to call POSIX commands directly in BS2000 without first calling a POSIX shell explicitly to permit their execution. The user can specify a single command, a list of commands (command sequence) or the name of a BS2000 file which contains a script.
The user must satisfy the requirements for calling a POSIX shell (see the START-POSIX-SHELL command).
The commands specified are forwarded to a POSIX shell without a syntax check being performed and called using the dot command. The environment variable EXECUTE_POSIX_CMD="YES"
is set in the shell. Querying variables (e.g. in /etc/profile or .profile) enables unwanted outputs to be suppressed when EXECUTE-POSIX-CMD is executed.
Processing of the EXECUTE-POSIX-CMD command ends only when all the commands which have been passed have been processed (i.e. all background processes which have been started are terminated). Processing can be aborted by pressing the K2 key twice.
The POSIX commands specified can optionally be logged in a BS2000 file (INPUT-LOG-FILE operand) and, if required, can be called again from this file.
By default, the command’s outputs are directed to SYSOUT (OUTPUT operand), but they can also be written to a file.
Details of permissible inputs (scope of the POSIX commands supported) and general information about working with the POSIX shell are provided in the “POSIX (Commands)” manual [28].
Format
EXECUTE-POSIX-CMD | Alias: ECXCMD | ||||||||||||||||||||
|
Operands
CMD=
Specifies the commands or scripts to be executed.
CMD = <filename 1..54>
Name of the BS2000 file from which the commands/command sequences are to be read.
CMD = list-poss (15): <c-string 1..100 with-low>
The command is specified explicitly. Multiple commands can be specified within a list in the form of a command sequence.
INPUT-LOG-FILE =
Specifies whether the inputs are to be logged.
INPUT-LOG-FILE = *NONE
The inputs are not logged.
INPUT-LOG-FILE = <filename 1..54 without-gen-vers>(...)
The inputs are logged in the specified BS2000 file.
WRITE-MODE = *REPLACE / *EXTEND
Specifies whether a file that has already been cataloged is to be overwritten or updated.
OUTPUT =
Specifies the place to which the command outputs are to be directed.
OUTPUT = *SYSOUT
Output is directed to the SYSOUT system file (i.e. in interactive mode, output on the monitor if nothing else is assigned).
OUTPUT = <filename 1..54>
The command outputs are to be written to the specified BS2000 file.
Return codes
(SC2) | SC1 | Maincode | Meaning |
---|---|---|---|
0 | CMD0001 | No error | |
x | 64 | CCM0999 | The shell command, command sequence or script supplies an exit status with the value x (not equal 0) which can be obtained from the SC2. |
Notes
Commands/scripts which are executed using EXECUTE-POSIX-CMD cannot read from the standard input because the latter is closed before a command/script is executed. Consequently, such commands/scripts receive EOF when they attempt to read from the standard input.
The POSIX commands which may under some circumstances read from the standard input (in the case of queries) are: rm, mv, bs2cp, mailxIn the case of EXECUTE-POSIX-CMD, stdout and stderr are not connected to a terminal but to a pipe. Commands/scripts which require stdout and stderr to be connected to a terminal therefore work either not at all or incorrectly. These commands/scripts use the CRTE functions isatty() and ttyname() to determine whether or to which terminal stdout and stderr are connected.
The POSIX commands which consequently might not work at all or only incorrectly are: tty, tabs, mesg, write, talk, more, patch, pax, nohup, ls, fg, bgWhen the shell command exec is executed with EXECUTE-POSIX-CMD, the current shell is unloaded and the mechanisms for forwarding outputs and/or the exit value of forked processes may be disabled.
The fc command is only effective for inputs outside scripts; it is therefore not suitable for use under /EXECUTE-POSIX-CMD.
The shell commands executed using EXECUTE-POSIX-CMD are not logged in the usual command memory ($HOME/.sh_history) but in a separate short command memory (HISTSIZE=100) under /tmp/.ecxcmd_sh_history_<user-name>.
As a result, the fc command only accesses the history of the EXEC-POSIX-CMD calls.Under EXECUTE-POSIX-CMD, command substitutions by means of ’command’ or $(command) are always executed in a subshell. In the POSIX shell, on the other hand, a number of commands are available which are substituted within the shell itself. Consequently, individual commands can behave differently from in the POSIX shell if the results are process-specific (e.g. ftyp and bs2file and accesses to variables or functions which have not been exported).
In the command sequence the definition of alias names using the alias command has no effect because the command sequence is executed using the dot command. If alias names are to be defined and used, the co.mmand sequence must be copied to a (temporary) POSIX file. The file must be assigned Execute permission and executed (not using the dot command).
The command sequence called using EXECUTE-POSIX-CMD is executed in a subshell which is generated internally by means of fork. The SYSFILE environment of the calling procedure is not available in this subshell. This can have an influence on BS2000 commands which are called using bs2cmd and on the POSIX commands lp, lpstat and cancel.