bpxwunix()
Function
Runs a shell
command and optionally:
- Provides its standard input.
- Traps its standard output.
- Traps its standard error.
- Exports a set of environment variables.
Parameters
- cmd
- The shell command that you want to run. The shell is run as /bin/sh -c followed by the string that you specify as the command. If a login shell is requested, the shell is run passing a single argument similar to the sh -Lc command.
- stdin
-
An optional argument, stdin is the name of a compound variable (stem) that contains input for the command.
stdin.0
must contain the number of lines that are to be redirected to the command. stdin.1, stdin.2, ... contain the lines.stdin can also be specified as:If this argument is not specified, the current stdin file is passed to the shell for stdin.- The string
STACK
, if the input is on the stack. DD:ddname
, if the input is to be read from an allocated DD.
- The string
- stdout
- An optional argument, stdout is the name of a compound variable (stem) that,
upon return, contains the normal output from the command. stdout.0 is
the number of lines output by the command. stdout.1, stdout.2, ...
contain the output lines. stdout can also be specified as:If stdout is not specified, the current stdout file is passed to the shell for stdout.
- The string
STACK
, if the output is to be returned on the stack. DD:ddname
, if the output is to be written to an allocated DD.
- The string
- stderr
- An optional argument, stderr is the name of a compound variable (stem) that,
upon return, contains the error output from the command. stderr.0 is
the number of lines output by the command. sterr.1, stderr.2, ...
contain the output lines. stderr can also be specified as:
- The string
STACK
, if the output is to be returned on the stack. DD:ddname
, if the output is to be written to an allocated DD.
- The string
- env
- An optional argument, env is the name of a compound variable (stem) that
contains environment variables for the command. env.0 must contain the
number of environment variables to be passed to the command. env.1, env.2,
... contain the variables in the form
variable_name=variable_value
. If env is not specified, the current environment is passed to the shell for stdin. - login
- An optional argument that specifies whether a login shell should be run.
- 0
- A login shell is not used.
- 1
- A login shell is used.
The default is 0.
- batch
- An optional argument that specifies whether the command should run as a UNIX background process
- 0
- The command runs in foreground synchronously with bpxwunix.
- 1
- The command runs in background under /bin/nohup, asynchronously with bpxwunix. The stdin, stdout, and stderr arguments cannot be specified for a background process; however, standard shell redirection can be used. Any output from the nohup command is directed to the file nohup.out.
The default is 0.
Usage notes
Return codes
BPXWUNIX returns the following return codes:- A return value in the range 0-255 is the exit status of the command.
- A negative return value indicates failure, and is usually a signal number. -256 is a general error code and a message is issued to the error stream describing the error.
- A number less than -1000 indicates a stop code.
Example
To trap output from the ls command and display it:
To send output from the previous example to word count and print the byte count: call bpxwunix 'ls -l',,out.
do i=1 to out.0
say out.i
end
call bpxwunix 'wc',out.,bc.
parse var bc.1 . . count
say 'byte count is' count
To trap output on stack and feed it to word count:
if bpxwunix('ls -l',,stack)=0 then
call bpxwunix 'wc',stack