0
我想從powershell調用帶參數的wlst/jython腳本。 (下面是一個簡化的版本)從powershell調用wlst/jython
hello.ps1
param (
[string]$cmd = "none"
)
echo "cmd - $cmd"
Switch ($cmd) {
"hello" {
Write-Host "Start hello ..."
$script='C:\_WORK_\hello.py'
& java -cp C:\bea\tpc\WEBLOG~1\server\lib\weblogic.jar weblogic.WLST $script
}
"main" {
Write-Host "w main $cmd"
$cmd='-c "hello"'
$script="C:\_WORK_\hello_main.py"
Write-Host "script: $script"
& java -cp C:\bea\tpc\WEBLOG~1\server\lib\weblogic.jar weblogic.WLST $script $cmd
}
Default {Write-Warning "Invalid Choice. Try again."
sleep -milliseconds 750}
} #switch
hello.py
print "Hello without main/args"
hello_main.py
import getopt
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hc:v", ["help", "command="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
command = None
verbose = False
for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-c", "--command"):
command = a
else:
assert False, "unhandled option"
print 'command: '+command
if (command == 'hello'):
print "if hello"
if __name__ == 'main':
main()
隨着「hello.ps1 -cmd主「劇本在」打印「命令後終止:'+ command' 我不明白爲什麼
>powershell c:\_WORK_\SAS\hello.ps1 -cmd main
cmd - main
w main main
script: C:\_WORK_\SAS\hello_main.py
Initializing WebLogic Scripting Tool (WLST) ...
command: hello
>powershell c:\_WORK_\SAS\hello.ps1 -cmd hello
cmd - hello
Status ...
Initializing WebLogic Scripting Tool (WLST) ...
Hello without main/args
把它另一種方式? – ReneHH