Friday, 27 September 2013

Obtain WebSphere fixpack information from within a Jython script and print to file

A bit tricky this one. I found loads of stuff telling you how to run the basic version info command but could find anything on how to pass arguments that you'd normally use on the command line such as "-maintenancePackages"  (i.e .$WAS_HOME/bin/versionInfo.sh -maintenancePackages)

In the end, a colleague and I de-compiled the com.ibm.websphere.product.VersionInfo class to find a solution which was to simply call the main method from that class two arguments.
  1. An array of Strings (as you'd expect) containing one element which is the String argument you'd normally use with versionInfo.sh (in my case -maintenancePackages)
  2. A boolean false (or zero) to prevent the program from exiting (because this for some reason causes your wsadmin shelll to exit)
 This works fine but for some reason this only dumps the output to STDOUT. I'm sure there's a more elegant way but I dealt with this by temporarily assigning System.out to a PrintStream object.  Here's the Jython code...


from java.io import File, PrintStream
import com.ibm.websphere.product.VersionInfo as vInfo

# Keep the existing Syste.out to one side
oldOut = System.out

# Set up a File and associated PrintStream
file = File("/tmp/vinfo.out")
ps = PrintStream(file)

# Point System.out at the PrintStream
System.setOut(ps)

# Call the main method from com.ibm.websphere.product.VersionInfo
# (NOTE: the second arg is a boolean to tell the program not to exit)
vInfo.main(['-maintenancePackages'],0)

# Reset Sysout.out back to STDOUT
System.setOut(oldOut) 


/tmp/vinfo.out nor contains your detailed versionInfo -maintenancePackages output

No comments:

Post a Comment