我在Windows服务器上使用Powershell作为主脚本语言,在这个特殊情况下,我使用它触发由wsadmin(WebSphere命令行)运行的Jython脚本
其中一个参数是文件的完整路径,除了路径分隔符后面紧跟字母“t”之外,其他参数都可以,Jython将其理解为“\t”,换句话说,是tab的特殊字符
我在脚本中添加了三行,如下所示
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)
如果脚本的参数没有“特殊字符”,则输出如下
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]']
但是,当文件以字母“t”开头时,它是另一个故事,它丢失并导致脚本失败
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]']
有没有关于如何避免这个问题的提示
解决此问题的最简单方法是保持py脚本不变,只需将参数封装在单引号中:
相关问题 更多 >
编程相关推荐