0

I want to create a batch file that starts the cmd.exe with some parameters. If I would type the cmd manually I would do it like this:

java -jar pathname

I will start .bat -> .bat starts cmd -> cmd starts command "java -jar pathname"

I already tried something like:

start cmd.exe "java -jar pathname"

Thank you already

2
  • 1
    start cmd.exe /k "java -jar pathname". I'll leave it to you to correctly apply the path(s) (or use start's /d switch). Commented Aug 16, 2021 at 12:34
  • Alright I tried both things and it works now. I thought I need to start the cmd seperately. My bad. Thank you both very much! Commented Aug 16, 2021 at 12:57

1 Answer 1

1

Actually the process is:

  • cmd starts bat -> bat starts java -> java runs jar.

So you do not start cmd.exe separately, it's already up and running.

If you want to change directory to reflect the location of the jar file then use the CD command.

@CD /D "L:\ocation\Of\Jar File"
@"P:\ath\To\java.exe" -jar "nameofjarfile.jar"

Or just provide the path to the jar file directly:

@"P:\ath\To\java.exe" -jar "L:\ocation\Of\Jar File\nameofjarfile.jar"

If you wanted to open a separate cmd.exe window, and leave it open, then use the START command:

@Start "" /D "L:\ocation\Of\Jar File" %SystemRoot%\System32\cmd.exe /D /K ""P:\ath\To\java.exe" -jar "nameofjarfile.jar""

To learn how to use the CD command, open a Command Prompt window, type cd /?, and press ENTER. And similarly for the START command, type start /?, and press ENTER.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.