0
votes

I'm trying to start a java process passing several parameters to it using a bat file. But the problem is that the cmd only jumps and doesn't show anything when using:

start cmd/C 

so making it

start cmd/K 

gives a pop-up cmd where this error is shown

'C:\New' is not recognized as an internal or external command, operable program or batch file.

For testing purpose for reproducing the problem you can start a java process by the example below.

I have searched for a solution, but the only thing that is similar to the problem was to use set and after that to work with the parameter. set "var=content"

The echo correctly prints the folder with many spaces like: "C:\New Folder and Spaces"
The code is below:

SET "currDir=%~dp0" 
echo %currDir% 
start cmd /K "%currDir%"..\jvm\jre\bin\java.exe -version

How can I pass the ~dp0 value even it has spaces in it without getting the above mentioned error? What if I should use it several times in a start command like:

start cmd /K "%currDir%"..\jvm\jre\bin\java.exe -version -Djava.awt.headless=true %JAVA_OPTIONS% -jar "%~dp0MyJar.jar" -home "%~dp0.." %*
1
I haven't understand: are you running the command directly from cmd or through a batch file? In cmd, there is no %~dp0, there is only %cd% which points to the current folder, the current working directory else called. Please clarify that for further help. - double-beep
1. It's a terrible habbit to partially quote paths; always quote them as a whole, like "%~dp0..\jvm\jre\bin\java.exe"! 2. start may interpret the first quoted string as a window title, so explicitly provide such, like start "" cmd ..., to avoid unexpected results. 3. There is no need for an interim variable %currDir%, you can use %~dp0 immediately. 4. Why so you use cmd /C or cmd /K to run java.exe? - aschipfl
I'm not sure why, but when " cmd /K" is removed the execution is ok and the error that next parameter is used as a command does not show anymore. - Vasil

1 Answers

0
votes

How about hoping for the existance of short file & folder names, since they never contain white spaces? Try:

set currDir=%~sdp0

(For more information visit ss64!)

Cheers, Nikolai