Index
Where I can start if I want to work with Open Source languages and packages in the IBM i environment?
Let’s say that, first of all, the best thing is to be updated with the operating system level of IBM i: since the latest system releases (starting from 7.1) IBM has increasingly improved the approach to Open Source solutions in the IBM i environment. … if I have an old V6R1 or worse V5R4 better to go horse racing, there are more likely to take home something!
Nothing better than a video to start from a Hello World application with Node.js …. our friend Yusy4Code is always ready with his basic tutorials, like this “Hello World to Node.js from IBM i”
Here are two sites from which to start for a classic Hello World with Python in an IBM i environment
Alternatively, a small step-by-step guide created by myself: following an IT-Jungle guide by Stephanie Rabbani (“Guru: Getting Started With Python On IBM i”) and some other posts around the web (“Introduction to Python for IBM i “By Mike Pavlak and” Pratical guide to Python “by Kevin Adler) I installed Python3 on my IBM i 7.2 machines.
In less than 20 minutes I tested the classic Hello World and downloaded a project by Alan Seiden Group with some fine examples of Python and IBM i from Github… isn’t it fantastic? The beauty is right here … compared to the classic RPG development with Python (and other languages available on IBM i) we can find around thousands of Open Source applications to be assembled together in our projects.
Here are the few steps taken, with some comments, and, following, the references of the material:
There is also a video by Moammed Yusuf explaining how to read DB2 for i tables from Python … all directly from access to PUB400.COM, therefore without even installing anything on your IBM i:
How to connect IBM i db2 using Python | yusy4code
I draw inspiration from an interesting discussion made on Midrange.com regarding the passage of parameters when dealing with the apostrophe (‘) or double quotes (“) where John Yeung and Kevin Adler exchange interesting ideas in this regard by taking up some comments by Barbara Morris from DW.
Case 1, simple parameter passage … two normal parameters
QSH CMD ('~ / script1.sh param1 param2')
Case 2, I have a third parameter with a space input (‘my house’) … in this case, we can safely use the double quotes to delimit the third parameter
QSH CMD ('~ / script1.sh param1 param2 "my house"')
Case3, I have a fourth parameter which in addition to spaces also has an apostrophe (damned Saxon genitive!) … in this case, we can use a double apostrophe (double your single quote) using it as if it were an escape
QSH CMD ('~ / script1.sh param1 param2 "my house" "my dog''s house"')
To better understand case 4 below, we must try to understand how escape quotes work in the CL and Bourne Shells environments (the QSH shell), in CL you can only use single-quote while in Bourne Shell you can use both single -quote that double-quote. This means that in the QSH environment we can simply use the single quote or the double quote where it is easier for us:
"This is John's apple." 'I said, "Can you hear me?"'
Or double the single-quote or double-quote to use our delimiter inside a string
'This Pascal string''contains two apostrophes' '' "I said," "Can you hear me?" ""
Another way is to use the backslash as an escape character
'This Pascal string ' s contains two apostrophes '' "I said, " Can you hear me? ""
The use of these escapes could, therefore, be for us when we want to pass parameters: let’s take this example … the classic “hello world” node.js application … which in this particular case, presents the parameters passed in an HTML page (*)
Here is an example of passing parameters via QSH to a Node.hs application
QSH CMD ('/ QOpenSys / pkgs / bin / node /home/Opensource/nodejs01/testparms.js myfirstparm mysecondparm "my house" "my dog''s house" "he said " Your dog''s house is very large "" ')
The source of the testparms.js application can be downloaded in this Github-Gist https://gist.github.com/Faq400Git/44b0aa307e6eda78354a4227f905e53d
The QSH shell script allows us to call scripts in the PASE environment from RPG or CL, we know this … but the thing that is not simple is to intercept QSH’s returncode / returnmessage.
There are several ways … one is to capture the QSH0005 message (procedure completed successfully) via QIBM_CMD_ESCAPE_MESSAGE … as in the examples of Midrange.com below:
https://code.midrange.com/d5909d4cc2.html – Capturing QSH0005 error messages
https://code.midrange.com/999b8e2180.html – Retrieve status code from msg QSH0005
See documentation here: https://www.ibm.com/support/pages/using-rcvmsg-and-monmsg-retrieve-qshell-messages – Using RCVMSG and MONMSG to Retrieve QSHELL Messages
A second method is to divert the output of QSH (QIBM_QSH_CMD_OUTPUT) as described in this IBM guide: https://media.techtarget.com/search400/downloads/Qshell_for_iSeries_ch2.pdf or in this post by Bradley Stone on FieldExit : Calling QSH command from RPG
When debugging a JOB QSH we generally use the STDOUT to view messages like console.log, and it’s convenient … but if the job is a scheduled JOB, things get complicated.
Among the many interesting utilities of Richard Schoen, in his Github repository, we also find this NodeOni that allows us to batch submit a JOB that executes a command from QSH with redirection of the STDOUT in the Joblog, in a file, in a spool file etc. .. really comfortable!
If we work with Open Source in an IBM i environment we know that it is much more convenient to connect with an SSH terminal (such as Putty) than to work with QSH from an IBM i 5250 environment because we can use different PASE shells, such as BASH, which make the clearly more productive work.
To set the default Shell we can work on our / home / user .profile or use the two techniques below:
CALL QSYS2.SET_PASE_SHELL_INFO ('* CURRENT', '/ QOpenSys / pkgs / bin / bash')
2. I install a dedicated utility like chsh via yum
yum install chsh
chsh -s / QOpenSys / usr / bin / ksh
or
chsg -s / QOpenSys / pkgs / bin / bash
An excellent article from which to start to understand the different shells available for the PASE environment is
Tech Tip: Be like a Turtle! by Jesse Gorzinski
If you are an RPG Developer I’m sure you’ll really like Rational Rdi to edit your code. When you have to edit Node.js or Python source code you can reach your files from IFS view in Remote System Explorer in Rdi.
When you double click on a .js of .py file Rational Rdi, by default, will open them with a text editor, but you can work on preferences to open a real editor for Node.js and Javascript or Pythom:
Change the file association to your favorite script editor, setting the default editor for .js and .py extensions
> Window > Preference > General > Editors > File Associations
There’s a good Mike Larsen’s post on IT Jungle : Guru: Calling RPG Programs From Python, Part 1
Take a look at this good Any Youens’ post on PowerWire: A NodeJS Website on IBM i – Updating Records
--- Roberto De Pedrini Faq400.comWe are pleased to receive and share this "tip & trick" from Patrick Rizzi, which introduces a technique that allows…
I take inspiration from a response by Michael Mayer on the Midrange.com mailing lists to someone who asked how to…
Businesses are increasingly seeking tools to enhance efficiency, collaboration, and resource management. Enterprise Resource Planning (ERP) systems provide a comprehensive…
Early April saw the release of the "Spring Version" of ACS Access Client Solution, version 1.1.9.5 Interesting new features especially…
If the packed agenda of sessions at Common Europe Congress 2024, June 3-6 Milan, wasn't enough for you, here's another…
Debugging functions with Visual Studio Code have been available for some time but this new version 2.10.0 simplifies the handling…
View Comments