Thanks a lot for everything you do for the IBMi community.
Here is my question: I have a Python program that takes two parameters: 1) IFS path and 2) Output_data. I pass these parameters from a CLLE program using QSH. The Python program populates the output_data with a list of all files and folders in the IFS path and ideally should return it to the calling CLLE.
I tested the Python program, and it is working correctly. However, the sys.argv[2], which contains the output_data from my Python program, is not getting populated in my CLLE program. My outputdata in CL program is always blanks. Can you please help me with this?"
My CL program:
Code: Select all
PGM
DCL VAR(&NULL) TYPE(*CHAR) LEN(1) VALUE(X'00')
DCL VAR(&QSHCMD) TYPE(*CHAR) LEN(2000)
DCL VAR(&ROOTPATH) TYPE(*CHAR) LEN(100) +
VALUE('/home/ibm_python')
DCL VAR(&OUTPUTDATA) TYPE(*CHAR) LEN(256)
DCL VAR(&OUTPUTCNT) TYPE(*INT) VALUE(0)
CHGVAR VAR(&OUTPUTDATA) VALUE(&OUTPUTDATA *TCAT +
&NULL)
CHGVAR VAR(&QSHCMD) +
VALUE('/QOpensys/pkgs/bin/python3 +
/lansrv/ibm_python/dev/deployifsobj/getifsi+
nfo.py ' *BCAT &ROOTPATH *BCAT &OUTPUTDATA)
QSH CMD(&QSHCMD)
ENDPGM
My Python program
Code: Select all
import os
import sys
# Retrieve parameters from command line
root_path = sys.argv[1]
output_data = sys.argv[2]
def get_next_level_items(root_path):
items = []
for item in os.listdir(root_path):
full_path = os.path.join(root_path, item)
if os.path.isdir(full_path):
items.append((item, 'directory'))
elif os.path.isfile(full_path):
items.append((item, 'file'))
items.sort(key=lambda x: (x[1], x[0]))
return [item[0] for item in items]
# Example usage
next_level_items = get_next_level_items(root_path)
output_data = next_level_items
sys.argv[2] = output_data
print("Sys.argv[2] : ", sys.argv[2])