Here is a snippet that would also validate the return code aka result

/* Execute the 'ls -l' command and capture its output */
call bpxwunix 'ls -l', , out., err.

/* Check the return code from BPXWUNIX */
if result = 0 then do
  /* If successful, display the captured standard output */
  say 'Command executed successfully.'
  say '--- Standard Output ---'
  do i = 1 to out.0
    say out.i
  end
end else do
  /* If there was an error, display the captured standard error */
  say 'Command failed with return code:' result
  say '--- Standard Error ---'
  do i = 1 to err.0
    say err.i
  end
end

exit 0

Here is the documentation for it

https://www.ibm.com/docs/en/zos/3.1.0?topic=services-zos-using-rexx-zos-unix-system


Thanks,
Kolusu

-----Original Message-----
From: IBM Mainframe Discussion List <[email protected]> On Behalf Of Sri 
Hari Kolusu
Sent: Sunday, August 3, 2025 8:50 AM
To: [email protected]
Subject: [EXTERNAL] Re: Obtaining the Return Code from bpxwunix in a REXX 
progrm,

Bpxwunix uses STDOUT and STDERR for the output and error processing.  So, add 
them to your CALL statement

call bpxwunix cmd,,,stdout.,stderr.

say "stdout output : "
do i=1 to stdout.0
  say stdout.i
end

say "stderr output : "
do i=1 to stderr.0
   say stderr.i
end

Thanks,
Kolusu

-----Original Message-----
From: IBM Mainframe Discussion List 
<[email protected]<mailto:[email protected]>> On Behalf Of 
[email protected]<mailto:[email protected]>
Sent: Sunday, August 3, 2025 8:22 AM
To: [email protected]<mailto:[email protected]>
Subject: [EXTERNAL] Obtaining the Return Code from bpxwunix in a REXX progrm,

Hello -.Im not well versed in Rex -.I'm executing a Rexx program in z/os from 
tso Option 6I can issue a call to call bpxwunix 'ls -l',,out..I do get some 
unpredictable results, and most of the time I get the desired results-In 
other-words the results of the call to bpxwunix for ls -la is not consistent .I 
have modified the code to obtain the Return code from the call to bpxunit 
-..Here is the current source:ADDRESS syscall- "chdir " cmdstrg call bpxwunix 
'Su'
RC = $?
Say 'RC From bpxunix .......'  $?
Say 'RC From bpxunix .......'  RC
call bpxwunix 'ls -l',,out.
RC = $?
Say 'RC From bpxunix .......'  $?
Say 'RC From bpxunix .......'  RC ..The issue is the Say command always results 
the value of $? not the specific return code -.How do I get the return code 
from bpxunix call and display it properly in a Rexx program505165 -Thank 
YouPaul D'Angelo.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to 
[email protected]<mailto:[email protected]<mailto:[email protected]<mailto:[email protected]>>
 with the message: INFO IBM-MAIN


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to 
[email protected]<mailto:[email protected]> with the message: 
INFO IBM-MAIN


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to