Reputation: 1313
I need to assign Standard out of java application added to an echo string of a bat file. Lets say java application writes "hello world" via System.out.println.
For an example I have a bat file mybat.bat.
@echo off
echo output=java -jar E:\FYP\MyApp\out\artifacts\MyApp_jar\MyApp_jar\MyApp.jar %1
which does not give the output=Hello world
How can I achieve that. Your help is really appreciated.
Thank You !
Upvotes: 1
Views: 3920
Reputation: 57282
As far as I understand you - you want to assign the output of the java to variable. May be this will do this for you:
@echo off
set "java_output="
setlocal enableDelayedExpansion
for /f "delims=" %%J in ('java -jar E:\FYP\MyApp\out\artifacts\MyApp_jar\MyApp_jar\MyApp.jar %1') do (
set "java_output=!java_output! %%J"
)
endlocal & set java_output=%java_output%
echo %java_output%
Upvotes: 3
Reputation: 70943
You need to use for
command to get the output of a program and assign it to a variable.
@echo off
for /F "tokens=*" %%o in ('java -jar E:\FYP\MyApp\out\artifacts\MyApp_jar\MyApp_jar\MyApp.jar %1') do set output=%%o
echo %output%
Upvotes: 2