1

I have a java program where I am expecting user to give some input and I want to use bash script to test the program. Though the program is working fine but I am not able to pass user input using script.

javac -d build ParkingLot.java
cd build/
java ParkingLot
"create_parking_lot 5"
"park hy-25-ysud-23 red"
"park hy-25-gfvd-23 white"
"park hy-25-ysfd-23 green"
"park hy-25-ysfd-24 black"
"park hy-25-ysfd-25 green"
"park hy-25-asfd-23 white"
"exit"

This 8 strings at the end is my input to program. How do I do this?

2
  • presumably you are getting your user input with String nextLine()? Commented Feb 15, 2020 at 15:53
  • I am using readLine() of BufferedReader Commented Feb 15, 2020 at 15:54

1 Answer 1

2

You can try Bash's here-document (one form of input redirection) in the script:

java ParkingLot << END
create_parking_lot 5
park hy-25-ysud-23 red
park hy-25-gfvd-23 white
park hy-25-ysfd-23 green
park hy-25-ysfd-24 black
park hy-25-ysfd-25 green
park hy-25-asfd-23 white
exit
END
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.