0
votes

I'm using Powershell as the main script language on our Windows servers, and for this particular case I use it to trigger a Jython script that is run by wsadmin (WebSphere command line).

One of the arguments is the full path to a file, all fine, except when the path separator is followed by for instance the letter 't', which then is understood by Jython as '\t', in other words the special char for tab.

I have added three lines in the script like this

print getTimeStamp() + " [DEBUG] This is the name of the script: ", str(sys.argv[0])
print getTimeStamp() + " [DEBUG] Number of arguments: ", len(sys.argv)
print getTimeStamp() + " [INFO] Script argument should be the patht to the property file: " , str(sys.argv)

If the argument to the script is without "special charaters", the output is like this

2021-01-14 15:55:48 [DEBUG] This is the name of the script:  e:\scripts\klpbpm\deployments\klporders-6336\stest-dns-aliaes.prop]
2021-01-14 15:55:48 [DEBUG] Number of arguments:  1
2021-01-14 15:55:48 [INFO] Script argument should be the patht to the property file:  ['e:\\scripts\\klpbpm\\deployments\\klporders-6336\\stest-dns-aliaes.prop]']

But when the file starts with the letter 't' it is a different story, it is missing and causing the script to fail.

2021-01-14 23:23:42 [DEBUG] This is the name of the script:  e:\scripts\klpbpm\deployments\klporders-6336   est-dns-aliaes.prop]
2021-01-14 23:23:42 [DEBUG] Number of arguments:  1
2021-01-14 23:23:42 [INFO] Script argument should be the patht to the property file:  ['e:\\scripts\\klpbpm\\deployments\\klporders-6336\test-dns-aliaes.prop]']

Any hints on how I could avoid this issue?

1
I think you should show the powershell code.Hernán Alarcón
@HernánAlarcón: Powershell code is not needed - I'm pretty sure that the same would happen if I triggered the script from command line. Notice the difference between the output when using str(sys.argv[0]) (causing the problem) and str(sys.argv). And then I realize that I maybe should try to drop the use of sys.argv[0] and sys.argvrhellem
The usual way is to use argparse. But I still think that your question needs some work to be a minimal, reproducible example. It should be like: I have this specific .py file with this specific content and I execute it using this specific command using this specific version of Python and I get this output which I think is wrong because...Hernán Alarcón
argparse is overkill for a single arg, additionally, because of the way wsadmin handles (or doesn't handle) exceptions thrown out of argparse, you don't get the pretty, well-formatted help messages if you pass the wrong number of args.F Rowe

1 Answers

0
votes

The easiest way to address this is to leave your py script as is and simply encapsulate the parameter in single quotes:

bash-4.2$ ./wsadmin.sh -f test.py 'e:\\dir1\\dir2\\ta.prop'
 WASX7209I: Connected to process "server1" on node DefaultNode01 using SOAP connector;  The type of process is: UnManagedProcess
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[e:\\dir1\\dir2\\ta.prop]"
[DEBUG] This is the name of the script:  e:\dir1\dir2\ta.prop
[DEBUG] Number of arguments:  1
[INFO] Script argument should be the path to the property file:  ['e:\\dir1\\dir2\\ta.prop']