system command - Part 1¶
With the PASE for i environment becoming ever more relevant and useful, IBM offers a few interesting API's and commands to combine the operating system's NFS (Native File System) and IFS (Integrated File System). One such command is
system it's possible to call CL-commands from within the PASE for i environment. What is interesting is that any spool file output is passed to STDOUT. What does that mean exactly?
We can enter the PASE for I environment and with it the IFS using the QP2TERM command. Once we're prompted with the shell, signified by the
$, we can call
system wrkactjob and get the following output:
The output is a pure string and as such one can't interact with it or its subfile as one would with the
WRKACTJOB QCMD command. Many IBM i veterans will find this output rather restrictive and not as useful, however for developers coming from the *nix world this opens up a wide array of possibilities. This kind of STDOUT output allows them to feed the
WRKACTJOB output to other common *nix tools such as
The screenshot above shows how I used the pipe symbol | to pipe (feeding the output as input) the output of
system wrkactjob into
grep multiple times.
grep can be considered a search/filter tool and I use it to filter out all the lines that I don't need. Lastly I use
awk to format the output. This particular formatting is what
ENDJOB requires. That means I could now use this output and use it in
system endjob to end those found jobs immediately.
At first this may seem verbose but shell commands, much like CL-Commands, can be scripted. As such one could write a small script or even just an alias that does all the above. One could call that script
endjobnow and call it like so:
The attentive reader will have noticed that I am not connecting to the IBM PASE for i environment using
QSH but rather via SSH (Secure Shell). The computer I'm sitting at right now does not even have a 5250 terminal emulator, but virtually all modern operating systems provide an SSH client. With
system and SSH I can still be productive on the i. Another interesting feature is the fact that SSH can be run in a non-interactive mode without starting a session. With the following SSH command I connect to the IBM i from my Windows machine, compile the SELECTROW program, bring the spool output of the compilation back to my Windows machine, and write it into the
1 2 3
This file is now a common
.txt file and can be opened in the editor of your choice. The following shows how it would look in Visual Studio Code:
After a while I wondered where the limits of
system are. I wondered if it's really possible to call any CL-command using
system and quickly found out that that's not the case.
WRKACTJOB example suggests, it's not possible to interact with the command like one would in a 5250 session and as such commands that require at least one interaction like
DSPLIB cannot be called using
system like so:
However, many of those commands also accept a parameter instead of an interaction and in the case of
dsplib that actually helps, because calling
does in fact work.
Unfortunately, this parameter alternative is not always possible. Calling
EDTLIBL throws following error:
1 2 3
Despite this limitation it is very apparent that using
system, common *nix tools, and a bit of creativity can open many new possibilities for working with the IBM i. In the next article I want to explore whether it's possible to use