Best way to pass a file path containing '\t' from Powershell script as argument to a Jython script

225 views Asked by At

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

There are 1 answers

0
F Rowe On

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