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 and RPG on IBM i

June 19, 2019/0 Comments/in Open Source, Python /by Alan Seiden

python trainingPython has been gaining momentum for building utility applications on IBM i, such as creating/reading Excel files, data transfer, process automation, calling REST APIs such as Salesforce and ServiceNow, and application monitoring.

Although some have said that Python would become the “new CL,” one limitation remains. While Python can easily call CL, RPG, and COBOL programs, calls in the other direction—from CL, RPG or COBOL to Python—required extra effort.

Update: May 2021

Updated instructions are provided at
INTEGRATE PYTHON INTO CL & RPG ON IBM i – 2021 UPDATE.
Richard Schoen will introduce you to QSHPYRUN, the next generation of PYRUN and part of Richard Schoen’s open source QShell on i Library – QshOni.

In this post we will introduce you to the PYRUN command, from Richard Schoen’s open source PythonOniLibrary (https://github.com/richardschoen/PythonOniLibrary), which makes it easy for traditional CL and RPG programs to call Python utilities and use their output.

Before trying PYRUN, 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: PYRUN

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

  • Allows various calling options, including the Python path and script name, a list of up to 40 input parameters as needed, and parameter switches that determine how PYRUN 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 PYRUN is special. With PYRUN, we can choose several ways to receive output from the script. By default, output is logged to the table QTEMP/PYSTDOUT. (On IBM i, every job has its own, unique QTEMP library.) PYRUN 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 PYRUN’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 PYRUN cleans up its internally used IFS temp files after processing.

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

Extend PYRUN using your own CL programs

You could make this even easier by writing your own wrapper program or CL command to call PYRUN to run a Python script, and then read PYSTDOUT 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 Python on IBM i

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

Tags: IBM i, IBMi, IBMiOSS, pyrun, Python
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 Alan Seiden https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png Alan Seiden2019-06-19 12:47:192023-01-03 18:14:56Integrate Python into CL and RPG on IBM i
Alan Seiden

About Alan Seiden

Alan works to preserve your investment in IBM enterprise systems by designing and implementing modernization strategies that leverage your existing business logic.

With a passion ...Read More

0 replies

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: Liam Allan Joins Seiden Group Link to: Liam Allan Joins Seiden Group Liam Allan Joins Seiden Group Link to: Gartner Questions ROI of Replacing Traditional IBM Platforms Link to: Gartner Questions ROI of Replacing Traditional IBM Platforms Gartner Questions ROI of Replacing Traditional IBM Platforms
Scroll to top Scroll to top Scroll to top