I don't know if it is possible, but I want to see the response of my .bat file in Java.
Or a boolean of something that I can see that everything were going well! And if there where some errors that I can see the errors in Java.
Thanks
You need to run it using the ProcessBuilder
(as long as you are running java 1.5 or above, if not check Alex's answer)
If you execute:
Process process = new ProcessBuilder("mybat.bat").command();
With the Process
you can call
InputStream errorStream = process.getErrorStream();
You will capture the output from the bat to stderr.
You can also use getOutputStream()
on process to get sdtout or check the return code with exitCode()
.
Take a look at these code samples for executing shell commands through java: Execute an external program
The code examples above do not utilize ProcessBuilder
and therefore are not limited to Java 1.5 and above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With