This document describes how to disable an exception stack trace from writing out to the screen from a WebLogic Scripting Tool (WLST) Python script file. A small demonstration is provided to show how the parameter works.
A Python script file, with try/catch code implemented, will display a stack trace to the screen when the script is executed with WLST.


Here is an example. The abc.py script file is using an invalid password:

try:
  connect('weblogic','invalid_password','t3://localhost:7001')
   print "Successfully connected"
except:
  print "Error while trying to connect!!!"
exit()
Execute the script file as follows, and observe the output shown:

/WLS/bea1030/wlserver_10.3/common/bin>wlst.sh abc.py
Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
This Exception occurred at Fri Apr 22 05:34:13 IST 2011.
javax.naming.AuthenticationException [Root exception is java.lang.SecurityExcept
ion: User: weblogic, failed to be authenticated.]
at weblogic.jndi.internal.ExceptionTranslator.toNamingException(Exceptio
nTranslator.java:42)
at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLIni
tialContextFactoryDelegate.java:783)
at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialCo
ntextFactoryDelegate.java:677)
.
.
.
.
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:473)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.jav
a:118)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Error while trying to connect!!!

Exiting WebLogic Scripting Tool.

Solution

To resolve the issue, use the following script which redirects the stack trace to a temp file and then deletes the temp file in the end:

import tempfile
import os
wlstOut = tempfile.mktemp(suffix="_wlst.txt")
redirect(wlstOut,"false")
try:
   connect('weblogic','weblogic','t3://localhost:7001')
   stopRedirect()
   print "Successfully connected"
except:
   stopRedirect()
   print "Error while trying to connect!!!"
os.remove(wlstOut)
exit()
Thus running the script now will give following output (excluding the stack trace for the exception), which is the goal:
/WLS/bea1030/wlserver_10.3/common/bin>wlst.sh abc.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...

Error while trying to connect!!!

Exiting WebLogic Scripting Tool.

0 Comments