0

I am running a command line program as follows:

java -jar myjar.jar -host localhost MonkeyProject/BAT_Login_Online_V1.mt

Which prints the following output:

result: OK

I am running the above command in a loop and want to read the output printed on the console in my script to make some decisions.

So how do i read it in the script?

2
  • with a pipe. What OS are you using? Commented Feb 23, 2016 at 20:34
  • Something like java -jar myjar.jar ... | myscript should work. Is that what you're asking? Is your script already written? Commented Feb 23, 2016 at 20:39

1 Answer 1

1

If using *nix:

var=`java -jar myjar.jar`

The output of the java program will be stored in var

If using Batch, you can do it by outputting into a file, then reading it back into a variable like this:

java -jar myjar.jar > file.txt
set /p var=<file.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.