4

While writing a deployment script for use with the WebLogic Scripting Tool (12.1.3), I came across this inconsistency between Python 2.2.1 and Jython 2.2.1. If you pass command line arguments to each, they are parsed differently, as noted by this test program:

$ cat pytest.py
import sys
print sys.argv

When run, here are the results with each interpreter.

CPython 2.2.1:

$ /cygdrive/c/Python22/python.exe pytest.py a b 'c,d,e'
['pytest.py', 'a', 'b', 'c,d,e']

Jython 2.2.1:

$ /cygdrive/c/jython2.2.1/jython.bat pytest.py a b 'c,d,e'
['pytest.py', 'a', 'b', 'c', 'd', 'e']

The reason I am using Jython 2.2.1 is because it is the Python implementation used by WLST, so I don't believe I can upgrade to a later version or use the CPython interpreter to circumvent the issue in my use case.

Is this a bug? Jython's parse seems counterintuitive. Is there a way to parse arguments the CPython way in Jython? Thanks in advance.

Contents of jython.bat (included with Jython install):

$ cat jython.bat
@echo off
rem This file was generated by the Jython installer
rem Created on Mon Oct 31 13:19:59 PDT 2016 by smcgloth

set ARGS=

:loop
if [%1] == [] goto end
    set ARGS=%ARGS% %1
    shift
    goto loop
:end

"C:\Program Files\Java\jre1.8.0_101\bin\java.exe" -Dpython.home="C:\jython2.2.1" -classpath "C:\jython2.2.1\jython.jar;%CLASSPATH%" org.python.util.jython %ARGS%
McGlothlin
  • 1,934
  • 15
  • 23
  • Wow, that is painfully old. Not an answer, but a quick Google search turns up resources saying something about [using WLST with Jython 2.7](https://technology.amis.nl/2015/10/04/how-to-use-wlst-as-a-jython-2-7-module/). That might be worth looking at. – user2357112 supports Monica Oct 31 '16 at 21:22
  • 1
    Can't reproduce on `Jython 2.2.1` on Linux (RHEL 7.2). Maybe something crappy in that batch file. – wim Oct 31 '16 at 21:22
  • I think its a classic append vs extend issue :-) – Illusionist Oct 31 '16 at 21:23
  • I know it's old. :( it's what my group is using though. I've also observed this in my Oracle Linux 7.2 environment, which prompted me to download Jython to my Windows environment to reproduce the issue with the script above. – McGlothlin Oct 31 '16 at 21:26
  • Could you post the contents of `jython.bat` please. – wim Oct 31 '16 at 21:36
  • 2
    http://bugs.jython.org/issue1599 – wim Oct 31 '16 at 21:44
  • Thanks for the link, wim. I tried the command outside the batch file and it worked. I'm still seeing this issue in my Linux environment but I think I'll just work around it at this point. I can't think of a simple way to replicate it for you guys because it's a Docker container running the WebLogic install, and I'm still pretty new to Docker. The weird thing is, Windows is not part of that environment at all so I'm not sure what's going on there... – McGlothlin Nov 01 '16 at 15:55

1 Answers1

1

I talked this over with my team this morning and we've figured out why I was experiencing this in a Linux environment, so I thought I'd post an answer in case it helps anyone else. One of my teammates wrote a startup script for the WLST that I had overlooked:

$ cat wlst
#!/bin/sh
wlst.sh -skipWLSModuleScanning $@

The culprit in my case was the -skipWLSModuleScanning flag. From the documentation:

Use this option to reduce startup time by skipping package scanning and caching for WebLogic Server modules.

It appears that skipping the package scanning must skip something crucial that affects the way Jython parses command line arguments.

Here are the results when skipping WLS module scanning:

$ wlst ~/pytest.py a b 'c,d,e'

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

['pytest.py', 'a', 'b', 'c', 'd', 'e']

And here are the results with the standard wlst.sh call, which is the result I would expect:

$ wlst.sh ~/pytest.py a b 'c,d,e'

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

['/home/tdmsadm/pytest.py', 'a', 'b', 'c,d,e']
McGlothlin
  • 1,934
  • 15
  • 23
  • Are you sure it wasn't something to do with the `$@`? I'm not a shell expert, but it looks like you might have a weird value of [`IFS`](https://bash.cyberciti.biz/guide/$IFS) or something like that that causes `$@` to split on `,`. [I think `"$@"`, with quotation marks, is what you need.](http://stackoverflow.com/questions/1575183/using-properly) – user2357112 supports Monica Nov 01 '16 at 17:19
  • I am not sure, as I am not a shell expert either. :) However I tried changing `$@` to `"$@"` and got the same result. – McGlothlin Nov 01 '16 at 17:41