Last Updated on 8 April 2020 by Roberto De Pedrini
iOSS-FAQ-001: Where to start
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!
iOSS-FAQ-002: Hello world with Node.js
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”
iOSS-FAQ-003: First steps with Python on IBM i, not just Hello World
Here are two sites from which to start for a classic Hello World with Python in an IBM i environment
- Guru: Getting started with Python on IBM i
- Say hello World to Java & Python on IBM i: A Mohammed Yusuf Video on Youtube
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:
- From IBM ACS Access Client Solution I choose “Tools – Open Source Package Management”
- Install or update if you don’t update the packages “yum” and “python3” and “git”
- I open a session with Putty in SSH on my IBM i (absolutely better than QP2TERM!)
- I update the PATH as indicated in the guide of Stephanie Rabbani (PATH = / QOpenSys / pkgs / bin: $ PATH export PATH)
- I create in my IFS home a small program with only the “print (” hello world “)” instruction (pay attention to the print in lower case and not in upper case as in the guide!)
- I run my first Hello World program: “python3 /home/faq400/hello.py” (again be careful to write python3 in lowercase!
- First step is taken… let’s see if I find something ready to test …
- I go to Github and find Club Seiden’s “Pyhon for IBM i example”
- I try to download the project with git “git clone https://github.com/Club-Seiden/python-for-IBM-i-examples.git” … but I have an HTTPS problem (“fatal: Unable to find remote helper for ‘https’ “)
- I fight a bit trying to disable the signature check but nothing to do …
- Then clone the repository with this command, which works very well “git clone git: //github.com/Club-Seiden/python-for-IBM-i-examples.git“
- I put myself in the directory of the “active job dashboard” service (cd / home / faq400 / python-for-IBM-i-examples / non-wheel / active-jobs-dashboard /)
- I run the Python application which generates an HTTP server waiting for me: “python3 ./server.py”
- I try the application on port 3333 to the ip address of my IBM i (http://192.168.xxx.xxx:3333/)
- It can be done!
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:
iOSS-FAQ-004: Passing parameters from QSH with apostrophes (‘single-quote) or quotes (“double-quote)
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
iOSS-FAQ-005: Return message from QSH
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
iOSS-FAQ-006: Manage the STDOUT of a QSH job (not just Node.js) in a file or in the Joblog of the job itself
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!
- NodeOni By Richard Schoen
- QshOni By Richard Schoen: Very similar to NodeOni but for a generic QSH command and not only Node.js
iOSS-FAQ-007: How to change the Shell of the PASE SSH environment
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:
- Imposed the Shell with a SQL Stored Procedure:
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
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.
Change the file association to your favorite script editor, setting the default editor for .js and .py extensions
> Window > Preference > General > Editors > File Associations
iOSS-FAQ-009: Call an RPG Program from Python (iToolkit)
There’s a good Mike Larsen’s post on IT Jungle : Guru: Calling RPG Programs From Python, Part 1
iOSS-FAQ-010: Node.js Web App on i – Updating records (By Andy Youens)
Take a look at this good Any Youens’ post on PowerWire: A NodeJS Website on IBM i – Updating Records--- Roberto De Pedrini Faq400.com