How to prevent popup of cmdprompt when executing dos script?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

How to prevent popup of cmdprompt when executing dos script?

#1 Post by pstein » 31 May 2014 23:27

I oftentimes want to start java GUI programs from a DOS Batch script. Therefore I put a code like this
in a DOS bacth script:

javaw.exe -jar mysample.jar parm1 parm2

which in turn starts java runtime and pass the *.jar (=java program) to it.

The disadvantage is that always a fat black Command prompt window appears on the screen which does not offer
anything execpt the start command echo.

What I want to achieve is that the Command Prompt window is silently suppressed and put completely into background. I even don't want to see it in (Win7) TaskBar.

If it is absolutely required it should be put automatically into SysTray.

How can I achieve this?

Extending the command above to e.g.:

start "" /B C:\WINDOWS\system32\cmd.exe /c "javaw -jar mysample.jar parm1 parm2"

does not help.

Furthermore I want to avoid shortcuts to the *.jar. So a batch script should be used somehow....

Peter

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to prevent popup of cmdprompt when executing dos scr

#2 Post by foxidrive » 01 Jun 2014 00:55

This should close the cmd window on launch, if javaw doesn't use it.


Code: Select all

@echo off
start "" javaw.exe -jar mysample.jar parm1 parm2

aGerman
Expert
Posts: 4744
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to prevent popup of cmdprompt when executing dos scr

#3 Post by aGerman » 01 Jun 2014 08:20

You could also create a shortcut with target ...

Code: Select all

javaw.exe -jar "C:\wherever\mysample.jar" parm1 parm2

... and maybe the path of the jar file in the "start in" field (if there are any dependencies in the working directory).
This way you don't need the CMD at all and you could edit it as simple as a Batch file.

Regards
aGerman

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Re: How to prevent popup of cmdprompt when executing dos scr

#4 Post by pstein » 01 Jun 2014 23:41

aGerman wrote:You could also create a shortcut with target ...

Code: Select all

javaw.exe -jar "C:\wherever\mysample.jar" parm1 parm2

... and maybe the path of the jar file in the "start in" field (if there are any dependencies in the working directory).
This way you don't need the CMD at all and you could edit it as simple as a Batch file.


The problem with this solution is that f***ing Windows prepends AUTOMATICALLY and ALWAYS the
javaw.exe with the absolute path. So when you save the shortcut as above and re-open it you will find a cmd like:

Code: Select all

"C:\Program Files (x86)\Java\jdk1.7_17\bin\javaw.exe" -jar "C:\wherever\mysample.jar" parm1 parm


Now what if I update/install a new java version? Or jump to 64bit java? Or copy the jar program to other computers with different java path? Or run the jar GUI program from USB stick on another computer?

....then the above shortcut always fails.

Those dumb developers at Microsoft do not allow relative resp. path independent javaw.exe specifications.

Thats why I am searching for a dos batch script based solution.

Thx anyway

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to prevent popup of cmdprompt when executing dos scr

#5 Post by foxidrive » 02 Jun 2014 03:17

pstein wrote:Thats why I am searching for a dos batch script based solution.


What didn't work about the suggestion I provided?

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Re: How to prevent popup of cmdprompt when executing dos scr

#6 Post by pstein » 02 Jun 2014 03:36

@foxidrive: Your solution works (thank you) but not the one from aGerman

Dragokas
Posts: 43
Joined: 30 Jul 2013 09:42
Location: Ukraine, USSR
Contact:

Re: How to prevent popup of cmdprompt when executing dos scr

#7 Post by Dragokas » 02 Jun 2014 08:58

Hi, pstein !

Use this command for ShortCut target instead:

Code: Select all

%SystemRoot%\system32\RunDll32.exe shell32.dll,ShellExec_RunDLL javaw -jar mysample.jar parm1 parm2


Best wishes, Alex.

Post Reply