Jython vs CPython syntax analysis - sys

When writing a script deployment for use with the Scripting WebLogic 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 indicated in this test program:

$ cat pytest.py
import sys
print sys.argv

At startup, 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 use Jython 2.2.1 is because it is the Python implementation used by WLST, so I do not believe that I can upgrade to a later version or use the CPython interpreter to get around the problem in my use case.

This is mistake? Jython parse seems controversial. Is there a way to parse the arguments of the CPython method in Jython? Thanks in advance.

jython.bat( Jython):

$ 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%
+4
1

, , Linux, , - . script WLST, :

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

-skipWLSModuleScanning. :

, , WebLogic Server.

, , - , , Jython .

WLS:

$ 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']

wlst.sh, :

$ 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']
+1

Source: https://habr.com/ru/post/1659452/


All Articles