Go to the top of the page

I am trying to start a java process through Powershell in Windows XP. Here is the command:

java.exe -cp .;./common.jar -Dcontext=atest1 -Dresourcepath=. DW_Install

So, the path to the classes. and. \ common.jar (I think java accepts the wrong slashes, right?) There are two environment variables: one "atest1" - the other. "and the class to execute main on is DW_Install (in the default package).

This command works in cmd.exe but is not a PS. What's happening? What does PS do when analyzing this command that CMD does not (or vice versa)?

Aaron

+5
source share
5 answers

The problem is that PS for some reason parses -Dresourcepath=.differently than cmd. What works

java -cp '.;.\common.jar' -Dcontext=atest1 "-Dresourcepath=." DW_Install

, , , (' "). - . , , PS, - . :

echo java -cp '.;.\common.jar' -Dcontext=atest1 -Dresourcepath=. DW_Install

:

java
-cp
.;.\common.jar
-Dcontext=etaste1
-Dresourcepath=
.
DW_Install

( , .)

echo java -cp '.;.\common.jar' -Dcontext=atest1 '-Dresourcepath=.' DW_Install

:

java
-cp
.;.\common.jar
-Dcontext=etaste1
-Dresourcepath=.
DW_Install

.

, , , java- Windows ( - ).

+7

PowerShell , PowerShell , .

Powershell . (dot- "sourcing" ), &.

, , :

PS> $classpath = ".;./common.jar"
PS> $env = "-Dcontext=atest1 -Dresourcepath=."
PS> $class = "DW_Install"

PS> . java.exe -cp $classpath $env $class
+5

, https://gaming.stackexchange.com/questions/24543/how-do-i-change-player-name-in-minecraft-multiplayer-in-offline-mode-in-linux

function mineCraftAs {
    Param (
        [parameter(mandatory=$true, HelpMessage="Minecraft character name." ,ValueFromPipeline=$true)]
        [string] $name
    )
    if(!(test-path $env:appdata)) { $(throw "Appdata not found at $env:appdata")}
    $private:minecraftPath=Join-Path $env:appdata .minecraft
    if(!(test-path $minecraftPath)) { $(throw "Minecraft not found at $minecraftpath")}
    $private:minebinPath=join-path $minecraftPath "bin"
    if(!(test-path $minebinPath)) { $(throw "Minecraft bin not found at $minebinPath")}

    $minebinPath | write-debug
    gci $minebinpath | write-debug

    #java -Xms512m -Xmx1024m -cp "%APPDATA%/.minecraft\bin\*" -Djava.library.path="%APPDATA%\.minecraft\bin\natives" net.minecraft.client.Minecraft '"'%1'"'

    echo java -Xms512m -Xmx1024m  -cp ('"'+$minebinPath+'\*"') ('-Djava.library.path="'+$minebinPath+'\natives"') net.minecraft.client.Minecraft ($name)

    $minecraftJob=& 'C:\Program Files (x86)\Java\jre6\bin\java.exe' -Xms512m -Xmx1024m  -cp ('"'+$minebinPath+'\*"') ('-Djava.library.path="'+$minebinPath+'\natives"') net.minecraft.client.Minecraft ($name)
}
minecraftas newbie
+3

:

java.exe -cp '.;./common.jar' -Dcontext=atest1 -Dresourcepath=. DW_Install

I believe that PowerShell interprets ;the class path as a command separator, thereby trying to run java -cp .and ./common.jar -D....

+1
source
start-process -nnw java "-cp .;./common.jar -Dcontext=atest1 -Dresourcepath=. DW_Install"
0
source

All Articles