Question

I'm trying to call wlst/jython/python from powershell

set classpath with setWLSEnv.cmd is not set in the right session? so I have tried to set -cp as argument

& C:\bea\tpc\weblogic1033\server\bin\setWLSEnv.cmd; 
$cp='C:\bea\tpc\WEBLOG~1\server\lib\weblogic.jar'
$wlst='weblogic.WLST'
$script='C:\domains\tpc\Domain\bin\status.py'
$java="C:\PROGRA~1\Java\JROCKI~1.0\bin\java"
& "$java $cp $wlst $script"
#or
. "`"$java`" -cp `"$cp`" $wlst `"$script`""
#or
& "`"$java`" -cp `"$cp`" $wlst `"$script`""

I have tried to quote the command string in various ways without success

The term '"C:\PROGRA~1\Java\JROCKI~1.0\bin\java" -cp "C:\bea\tpc\WEBLOG~1\server\lib\weblogic.jar" weblogic.WLST "C:\domains\tpc\SasTT pcDomain\bin\status.py"' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:_WORK_\SAS\statusAll.ps1:15 char:2 + . <<<< ""$java" -cp "$cp" $wlst "$script"" + CategoryInfo : ObjectNotFound: ("C:\PROGRA~1\Ja...\bin\status.py":String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Was it helpful?

Solution

When you use the call operator &, the next token needs to be the name of a command and nothing else. So instead of this:

& "$java $cp $wlst $script"

Try this:

& $java $cp $wlst $script

Sometimes getting arguments to native exes can get ugly. A technique that usually works but is unsafe if any of your arguments come from user input is this:

Invoke-Expression "$java $cp $wlst $script"

OTHER TIPS

In addition to the trouble with how you're formatting your command into a string, setWLSEnv.cmd is a script for the Windows Command Prompt. PowerShell cannot execute this file; it does not know how to interpret it, much like how Notepad does not know how to interpret a docx file. Windows associates .cmd files with the command prompt, so your first line is equivalent to

& cmd.exe /c C:\bea\tpc\weblogic1033\server\bin\setWLSEnv.cmd

(Note that the semicolon is unnecessary since you don't have any other commands on the same line.)

This creates a new process using cmd.exe. This new process executes the batch file, setting the environment variables you expect, and then the process exits, discarding the environment changes.

If you need setWLSEnv.cmd to set environment variables prior to executing your program, you should write a batch file that calls it instead of a PowerShell script. Otherwise, you will need to find or write a PowerShell equivalent to set up your environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top