New QSHONI Commands: Integrate Python, PHP, Java with CL & RPG

QSHONI integration for IBM i RPG, CL and open sourceA few years ago I introduced you to my QShell on i utility – QSHONI. QSHONI makes it easy for traditional CL, RPG, and COBOL programs to call Python utilities and other QShell/PASE utility programs (PHP, Node, Java, etc.) and directly use their output. QSHONI opened up a whole new world of integrations to open-source apps from traditional IBM i applications.

I keep thinking I will run out of interesting things to add to the library, but the ideas keep on flowing.

In this post I will update you on QSHPHPRUN, QSHCALL and QSHPYCALL, recently added features. As a primer for this post, you can read our last QSHONI update from March 2023.

I plan to write about several other new features and enhancements in further blog posts.

New CL Commands

QSHPHPRUN – Run PHP Script via QShell 

PHP scripts aren’t just for web apps. You can write command (CLI) utilities that can be called from CL and RPG. The QSHPHPRUN CL command is a nice convenience wrapper for running PHP scripts from a CL or RPG application. You can specify up to 40 PHP command line arguments to run along with the selected script file.

A good example of a useful PHP script to call might be something that calls a web service and returns JSON results. Or perhaps you want to upload or download a file to SharePoint, OneDrive or Amazon S3. You can write a command line-driven PHP script that accepts parameters, and transparently use it from CL, RPG and even COBOL.

The QSHPHPRUN command makes it easy to call PHP scripts from CL and RPG without having to concatenate long commands.

Example of a PHP call passing four CL arguments:

QSHONI/QSHPHPRUN SCRIPTDIR('/myphp') SCRIPTFILE(dosomething.php) ARGS(&ARG01 &ARG02 &ARG03 &ARG04)

Several other optional parameters can be passed to override the defaults, including the location of the PHP binary file.

QSHCALL and QSHPYCALL – Run QShell Command Line or Python Script and Return Parms 

Those of us who are classic RPG, COBOL and CL developers are used to calling programs and returning parameter values via CALL/PARM. These CL commands can be used to run any script or, specifically, a Python script via QSHEXEC and return up to 10 parameter values from the STDOUT log info.

Note: The QSHCALL or QSHPYCALL CL commands must be embedded in a CL program since they both return parameter values to the calling CL, RPG or COBOL program.

The special prefix format we look for in the STDOUT log to return values from STDOUT is as follows.

All data after the special RETURNPARMxx: keyword is returned as a value for the selected parameter. Example: For the RETURNPARM01: I am a return value 1 value below it simply returns: “I am return value 1” in the first return parameter and discards the prefix portion of the log entry.

RETURNPARM01: I am return value 1
RETURNPARM02: I am return value 2
RETURNPARM03: I am return value 3
RETURNPARM04: I am return value 4
RETURNPARM05: I am return value 5
RETURNPARM06: I am return value 6
RETURNPARM07: I am return value 7
RETURNPARM08: I am return value 8
RETURNPARM09: I am return value 9
RETURNPARM10: I am return value 10

You’ll find additional details on these two commands in the QSHCALL documentation and QSHPYCALL documentation.

Stay in touch

Make sure to visit the QShell on i GitHub site to stay up to date on QSHONI enhancements. Also feel free to suggest new commands or enhancements in the Github site issue pages, and to contribute!

For reliable answers to all of your questions about using open source on IBM i, check out Seiden Group’s SmartSupport program.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.