2

Apologies if duplicate, I want to run a jar file from command prompt, So instead of going to the specific path can i create a batch file, Simply double click on batch file will do my task, I found something at [1]: Run a Command Prompt command from Desktop Shortcut but it do not work in my case, I want to run java -jar squirrel-sql.jar

I would like to make a batch file that:

1)Opens cmd.exe

2)Within that Command Prompt runs java -jar squirrel-sql.jar which is present on desktop

3)Leaves the window open so that I can run additional commands if I wish to How can I do this?

Community
  • 1
  • 1
Anand Deshmukh
  • 169
  • 3
  • 20

1 Answers1

0

Save the following as squirrel.bat:

java -jar squirrel-sql.jar

REM /P causes SET to prompt and wait for Enter.
REM The underscore is used to ensure that "sure" is not already
REM an environment variable.
set /p _sure="Do you want to exit? [press Enter]"

REM /I causes a case-insensitive comparison
if /I NOT "_sure"=="y" (
  REM /B exits the batch script but not the CMD window
  exit /b
) else (
  REM Any other modifications
)
shoover
  • 3,071
  • 1
  • 29
  • 40
MangduYogii
  • 935
  • 10
  • 24
  • use this code and save a .bat file extention and duble click on that bat file it will run fine – MangduYogii Jul 20 '18 at 08:53
  • Welcome to Stackoverflow! Even though your answer might be valid, it will not be informative to any future user having the same problem. Could you please elaborate in your answer on what your code does and how it fixes the problem in the question? – Christopher Chiche Jul 20 '18 at 09:37
  • This is used to run jar and perform different operation without closing cmd.as per user wish if they wish exit from jar but not cmd. – MangduYogii Jan 21 '19 at 12:51