-1

I'm trying to understand this batch job file, there are two and the first is returning an exit code of 0:

set JAVA_HOME="C:\Program Files(x86)\Java\jre1.8.0_221\bin"

%JAVA_HOME%\java -Xms125M -Xmx512M -Djava.ext.dirs=lib org.pg.test.ListOutput > output.txt 2>exception.txt

And this second one is returning an exit code of 1:

set JAVA_HOME="C:\Program Files(x86)\Java\jre1.8.0_221\bin"

%JAVA_HOME%\java -Xms125M -Xmx512M -Djava.ext.dirs=lib org.pg.test.ListOutput 1 0 > output.txt 2>exception.txt

What does the 1 & 0 after the file name mean exactly? Why is this making it return an exit code 1?

Both files run normally, with a successful output in output.txt.

Trying to google the exact syntax this is in (batch files were not written by me) but maybe I'm searching for the wrong thing.

stewie
  • 1
  • 1
  • Does this answer your question? [Why is no string output with 'echo %var%' after using 'set var = text' command in cmd?](https://stackoverflow.com/questions/26386697/why-is-no-string-output-with-echo-var-after-using-set-var-text-command-i) There must be used on Windows `set "JAVA_HOME=C:\Program Files(x86)\Java\jre1.8.0_221"` with first `"` left to the environment variable `JAVA_HOME` and not right to the equal sign and there must be specified the path to the Java directory containing the subdirectory `bin` as described by Oracle in Java documentation. – Mofi Jan 26 '23 at 06:05
  • There must be used next `"%JAVA_HOME%\bin\java.exe"` instead of `%JAVA_HOME%\java` to run the Java executable. `>output.txt 2>exception.txt` is modified by `cmd.exe` on execution to `1>output.txt 2>exception.txt` That is normal and documented by the Microsoft documentation about [Using command redirection operators](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490982(v=technet.10)). I don't know why there should be `0` left to the redirection operator which redirects __STDOUT__ (standard output) with handle number 1 to a file. I can't see that on my PC. – Mofi Jan 26 '23 at 06:10
  • If I see correctly, the only difference between the commands is the `1 0`. These are the parameters passed to the `main` function in `ListOutput`, and you did not show here, what this function is doing to its parameters. In any case, the exit code is set by the `main` function. – user1934428 Jan 26 '23 at 08:48

1 Answers1

1

The documentation for the java command is found

  • here for JDK/JRE version 18 (a fairly recent version), and
  • here for JDK/JRE version 1.8 for Windows, which appears to be what you're using.

The 1 and the 0 after the class name are arguments that will be passed to the Java program when it runs. As for why this causes the program to exit with a particular exit code, that depends on what the program does. It's impossible to answer that without seeing the source code of the program.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
  • Thank you! I was thinking it had to do with the file descriptor of 2 which takes the error output. I don't have access to that source code currently, but if I were to recreate it, where would I put the java file with the main method? – stewie Jan 26 '23 at 02:49
  • The directory structure has to match the package name, and the file name has to match the class name, with `.java` added. In other words, your path needs to be `org\pg\test\ListOutput.java`. Case matters. As for the top of the directory structure, you can put it wherever you like, but you need to be at the top of the directory when you compile. – Dawood ibn Kareem Jan 26 '23 at 02:53