Windows executing bat/cmd

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


Hello,

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 ProcessImpl.java 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?

Gruss
Bernd

Sample code: it does allow bat/cmd:
- http://stackoverflow.com/questions/21553379/createprocess-is-able-to-execute-batch-files-but-documentation-says-the-opposit
JDK7u code:
- http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/file/1ed30c084e3d/src/windows/native/java/lang/ProcessImpl_md.c
- http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/file/1ed30c084e3d/src/windows/classes/java/lang/ProcessImpl.java
MSDN CreateProcessW
- http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx
MSDN Sample usage:
- http://msdn.microsoft.com/en-us/library/windows/desktop/ms682512%28v=vs.85%29.aspx






More information about the core-libs-dev mailing list