Thursday, 27 February 2014

Executing external Python/Jython scripts from within WebSphere Application Server's wsadmin tool

One of my ISSW UK colleagues had asked how to invoke an externally located Python/Jython script from inside the wsadmin tool.

This is different from the normal method of starting wsadmin and directing it to load a file at startup e.g.

$ ./ -lang jython -c 'AdminApp.list()'

This is subtly different - one is already in wsadmin and wants to go fetch / execute an external script.

Well, thanks to the IBM Connections 2.5 documentation (!), here it is: -


My colleague also pointed out that one can execute OS commands from within a Python shell e.g.

$ python

Python 2.6.6 (r266:84292, May 27 2013, 05:35:12) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import os
>>> os.system("/bin/ls")
ConfigBPM.err   ConfigNetworkPort.err  ConfigPWD_USER.err  License.err
ConfigBPM.out   ConfigNetworkPort.out  ConfigPWD_USER.out  License.out
ConfigLocale.err  ConfigNTP.err  ConfigSSH.err      _nowait
ConfigLocale.out  ConfigNTP.out  ConfigSSH.out
ConfigNET.1.err   ConfigPWD_ROOT.err  ConfigVNC.err      ovf-env.done
ConfigNET.1.out   ConfigPWD_ROOT.out  ConfigVNC.out

So, putting it all together, here's me executing an external Jython script from within wsadmin, where said Jython script gets a directory listing: -

$ /opt/IBM/BPM/v85/profiles/BPMPCDmgrNode/bin/ -lang jython -user wasadmin -password password

WASX7209I: Connected to process "dmgr" on node BPMPCDmgrNode using SOAP connector;  The type of process is: DeploymentManager
WASX7031I: For help, enter: "print"

Hello World!
Here comes the directory listing

and here's the Python script: -

$ cat /tmp/ 
import sys;
import os;

print "Hello World!"

print "Here comes the directory listing"


No comments:

Yay, VMware Fusion and macOS Big Sur - no longer "NAT good friends" - forgive the double negative and the terrible pun ...

After macOS 11 Big Sur was released in 2020, VMware updated their Fusion product to v12 and, sadly, managed to break Network Address Trans...