Windows executing bat/cmd

Bernd Eckenfels ecki at
Sat Oct 4 23:54:13 UTC 2014


I noticed that MSDN CreateProcess(W) talks about using "cmd /c" for
executing .bat and .cmd files:

"To run a batch file, you must start the command interpreter;
set lpApplicationName to cmd.exe and set lpCommandLine to the
following arguments: /c plus the name of the batch file."

However the JDK implementation seems to accept an executable path pointing
to a *.bat or *.cmd file.

When I look through the windows specific code for and
ProcessImpl_md.c it looks like Java is expecting this (undocumented?)
behaviour and even supporting it (as it parses cmd+bat commands
stricter than exectables and looks for MZ signature etc).

I don't see a comment discussing the not-documented behaviour of
CreateProcessW and also there is no API Doc encouraging or deprecating
the use of cmd[0]="bla.bat" in Process Builder (or I have missed it).

Anybody can enlighten me?


Sample code: it does allow bat/cmd:
JDK7u code:
MSDN CreateProcessW
MSDN Sample usage:

More information about the core-libs-dev mailing list