Seiden Group
Modern Development & Open Source for IBM i
  • Link to LinkedIn
  • Link to Mail
  • Home
  • Seiden PHP+
    • Seiden PHP+
    • Install & Learn
    • SmartSupport
    • PHP Migrations & Upgrades
    • Success Stories
    • Free PHP Assessment
    • Documentation
    • What’s New (Changelog)
  • IBM i Services
    • Development
    • Training & Mentoring
    • Open Source Setup & Upgrades
    • SSL/TLS Install & Learn
    • Performance
  • Support
    • Open Source & PHP
    • VS Code for i
    • Developer Support
    • Support Success Stories
  • VS Code for i
    • Support
    • Training
    • Code for i Resource Guide
    • Getting Started Videos
    • Code for IBM i Fridays
  • Free Stuff
    • IBM i Strategy & Tips
    • PHP Upgrade Assessment
    • CNX Valence Assessment
    • VS Code for IBM i Resources
    • Code for IBM i Fridays
    • QCachegrind Download
    • PHP Toolkit for IBM i Resources
    • Qshell on i Library
  • Blog
  • About
    • About Our Team
    • About Alan Seiden
    • Speakers & Sessions
    • In the News
  • Contact
  • 201.447.2437
  • Search
  • Menu Menu

Seiden Group Blog

Integrate Python into CL & RPG on IBM i – 2021 Update

May 14, 2021/1 Comment/in Open Source, Python, RPG /by Richard Schoen

python trainingPython on IBM i has proven itself as a tool for building utilities to create/read Excel files, transfer data, automate processes, call REST APIs such as Salesforce and ServiceNow, monitor applications, and more. What was missing was an easy way to use the power of Python from CL and RPG.

In 2019 we introduced you to the PYRUN command for running Python scripts from CL and RPG programs.

In this post we introduce you to QSHPYRUN, the next generation of PYRUN and part of Richard Schoen’s open source QShell on i Library – QshOni. QSHONI makes it easy for traditional CL and RPG programs to call Python utilities and use their output. This is supported via the QSHPYRUN command. QSHONI also supports general calls to other QShell, PASE and bash calls via the QSHEXEC and QSHBASH commands. This means QSHONI commands support calling Python, Node, PHP, Java and all things open source, making QSHONI much more versatile than the standalone PYRUN command was. The QSHONI commands can safely live side-by-side with the PYRUN command because they live in different IBM i libraries. This allows for migration to QSHPYRUN to  happen as needed.

Before trying QSHPYRUN, you must install the Python language itself, as described by Stephanie Rabbani in the linked IT Jungle Guru tip.

The challenge

Because Python runs in PASE, traditional IBM i jobs must spawn a new PASE job to run the selected Python script. The calling application can’t consume the PASE output without a little help.

A solution: QSHPYRUN

The QSHPYRUN command is a front-end wrapper command that does the following:

  • Allows various calling options, including the Python path and script name, automatically setting the path to the IBM Open Source packages (via parameter: SETPKGPATH=*YES), passing a list of up to 40 input parameters as needed, and parameter switches that determine how QSHPYRUN should return the Python script’s results.
  • Calls the Python script.
  • Captures Python’s output from standard output (STDOUT) and sends it to the requested location so that the output can be consumed by the calling job or other applications.

Choose where you would like your output

We’ve been calling PASE scripts (PHP, Python, Node, more) from CL and RPG for years, but QSHPYRUN is special. With QSHPYRUN, we can choose several ways to receive output from the script. By default, output is logged to the table QTEMP/STDOUTQSH. (On IBM i, every job has its own, unique QTEMP library.) QSHPYRUN can also return output via several other options:

  • DSPSTDOUT – Display the outfile contents within your interactive (5250 mode) program (good for debugging.)
  • LOGSTDOUT – Place STDOUT log entries into the calling job’s job log.
  • Note: Don’t log to the job log if you expect your Python script to output thousands of lines to STDOUT. You will litter your IBM i job log with superfluous info in many cases or you may even kill the IBM i job if the job message queue hits its limit and the IBM i job is not set to wrap its job log. You can easily identify QSHPYRUN’s messages by its CPF message ID of PYM9898.
  • PRTSTDOUT – Print STDOUT to a spool file. Handy for batch jobs.
  • DLTSTDOUT – This option ensures that QSHPYRUN cleans up its internally used IFS temp files after processing.
  • IFSSTDOUT – This option ensures that QSHPYRUN can capture the entire IFS log to another IFS log file. This option coupled with the IFSOPT parameter to *APPEND or *REPLACE the specific IFS log file can be a good way to aggregate the result of multiple command calls to QSHPYRUN, QSHEXEC or QSHBASH to a single log file.

Once your Python script has completed and the QSHPYRUN command returns without any errors, your CL, RPG, or COBOL application can then read QTEMP/STDOUTQSH to process any useful data such as return values.

Extend QSHPYRUN using your own CL programs

You could make this even easier by writing your own wrapper program or CL command to call QSHPYRUN to run a Python script, and then read STDOUTQSH for return values and send them back through your custom CL command return parameters. Example: say you wrote a Python script to read a database and generate an Excel file with an auto-generated name. You need to get the name back. Python could write the name to STDOUT so that the calling CL or RPG application could read it in and then do something with the new Excel file. There are limitless uses for running Python scripts from traditional IBM i applications and then consuming the result for use.

Create your own utilities with the QSHPYRUN Command

This post was just a quick introduction to the QSHPYRUN command. In future posts, or during training or consulting engagements, we can teach you how to use QSHPYRUN and the other QShOni commands in your own applications. Enjoy Python on IBM i and send us your feedback.

Tags: IBMiOSS, pyrun, Python, qshell, RPG
Share this entry
  • Share on Facebook
  • Share on X
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Reddit
  • Share by Mail
https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png 0 0 Richard Schoen https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png Richard Schoen2021-05-14 13:46:412021-10-14 17:27:58Integrate Python into CL & RPG on IBM i – 2021 Update
Richard Schoen

About Richard Schoen

Richard likes to eat new application development languages for breakfast. His specialties span a myriad of languages, including PHP, Python, Node.js, Java, HTML, Javascript, ...Read More

1 reply
  1. Kevin Monahan
    Kevin Monahan says:
    May 26, 2021 at 6:41 am

    Thank you Richard. I have downloaded and compiled the code package to our IBMi. Next I’ll find some time to figure out how it works and what it can do for us! Just starting my Python journey after 35 years on IBM mid-range.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel 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.

SUBSCRIBE
Open Thinking
Monthly IBM i Strategy & Tips
  • This field is for validation purposes and should be left unchanged.

IBM i Development

  • RPG, COBOL, SQL, Node,
    PHP, Python, Valance, etc.
  • Modernization. Integration.
  • Web and API Solutions
  • Legacy Maintenance
    ...
LET'S GET IT DONE!

Recent Posts

  • Do You Need IBM i Observability?
  • PHP 8.6 is Coming Soon to IBM i
  • Safer npm installation is on the way for Node.js (and all JavaScript)
  • Access Modern Security for IBM i and Connected Web Environments
  • IBM i: A Natural Platform for Agentic AI
  • PHP on IBM i in 2026: The Modernization Engine
  • Your “AS/400” Is a Modern IBM i Platform
  • MCP + AI for IBM i Teams (with a MongoDB example)
  • GnuPG PHP Extension for IBM i: Now Included with Seiden Support
  • Getting Started with Code for IBM i: A Lunch & Learn Video

SEIDEN GROUP: Modern Development & Open Source for IBM i

Home   |   Seiden PHP+   |   IBM i Services  |   Support   |   VS Code for i   |   Free Stuff   |   Blog  |   Privacy Policy  |   Contact         201.447.2437

© 2026 Seiden Group, LLC
  • Link to LinkedIn
  • Link to Mail
Link to: Tutorial: Integrate Node.js with RPG without a Connector Link to: Tutorial: Integrate Node.js with RPG without a Connector Tutorial: Integrate Node.js with RPG without a Connector Link to: Using PHP with Rational Developer for IBM i Link to: Using PHP with Rational Developer for IBM i Using PHP with Rational Developer for IBM i
Scroll to top Scroll to top Scroll to top