0

I'm using WLST to execute some scripts to deploy some applications in Weblogic.

I'm using getopt library in Python to parser command line arguments.

I created a script to download some files by FTP.

To do this, the user must inform the 'ftpurl', 'ftpusername' e 'ftppassword' options and respective values.


import getopt
# -*- coding: utf-8 -*-

#=======================================================
# MAIN
#=======================================================
args = sys.argv
print 'Informed arguments: '
print args
for index in range(len(args)):
    if (":\\" in args[index]) :
        print
        print 'Removing arguments with file path'
        print args[index]
        del args[index]
        break
optlist, argsNotExpected = getopt.getopt(args, '', ['ftpurl=', 'ftpusername=', 'ftppassword='])
print
print 'Found options: '
print optlist
print
print 'Not expected arguments: '
print argsNotExpected

The argument value "test123!@#$%*()_-" that have many special characteres works.

java weblogic.WLST C:\\Ambiente\\scripts\\python\\getoptTest.py --ftpurl=ftp.test.com --ftppassword=test123!@#$%*()_- --ftpusername=usertest

Result:

Informed arguments:
['C:\\\\Ambiente\\\\scripts\\\\python\\\\getoptTest.py', '--ftpurl=ftp.test.com', '--ftppassword=test123!@#$%*()_-', '--ftpusername=usertest']

Removing arguments with file path
C:\\Ambiente\\scripts\\python\\getoptTest.py

Found options:
[('--ftpurl', 'ftp.test.com'), ('--ftppassword', 'test123!@#$%*()_-'), ('--ftpusername', 'usertest')]

Not expected arguments:
[]

But when I passing "test&123!@#$%*()_-" with "&" character, the value is break and the rest of the arguments are ignored starting from "&".

java weblogic.WLST C:\\Ambiente\\scripts\\python\\getoptTest.py --ftpurl=ftp.test.com --ftppassword=test&123!@#$%*()_- --ftpusername=usertest

Result:

Informed arguments:
['C:\\\\Ambiente\\\\scripts\\\\python\\\\getoptTest.py', '--ftpurl=ftp.test.com', '--ftppassword=test']

Removing arguments with file path
C:\\Ambiente\\scripts\\python\\getoptTest.py

Found options:
[('--ftpurl', 'ftp.test.com'), ('--ftppassword', 'test')]

Not expected arguments:
[]
'123!@#$%*' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.

Can anyone give a tip?

1 Answers1

0

This is a problem with the shell, since & is interpreted as a special character. In bash, it sends the command to the background, whereas on cmd.exe it's used to chain multiple commands.

This means you can't fix it in the script, but you can quote your arguments instead:

getoptTest.py --ftpurl=ftp.test.com --ftppassword="test&123!@#$%*()_-" --ftpusername=usertest

Alternatively, you can use ^& to escape ampersands (https://stackoverflow.com/a/27960888/12833309)

Deniz Genç
  • 107
  • 1
  • 8