bash interactive script pass input

2.6k Views Asked by At

I'm running the following interactive Jar.

java -jar script.jar
  argument-line-here
  \n 

Now I'm creating a bash script which runs the jar file. How do I pass the argument line and the conformation "\n" to this interactive script? these are input lines for the script.

This question has some answers, expect is not yet installed on my system and i do not have sudo.

edit: The .jar also doesn't return any text. it only expects 2 lines. (one with arguments and one with a conformation enter). I also cannot edit the Java application. It is not my script. If I could've I would've.

Things I have tried but didn't work.

java -jar myscript.jar
<<< &"argument1 argument2 argument3 argument4" <<< $"\n"

and

java -jar java -jar myscript.jar > tmp.txt 
expect ""
send "argument1 argument2 argument3 argument4"
expect ""
send "\n"
1

There are 1 best solutions below

1
On BEST ANSWER

If you want to redirect the normal standard input of the program, you could use so called "here documents" (see e.g. the BASH manual page):

java -jar script.jar <<EOF
your input here
EOF

That means standard input (a.k.a. stdin) is redirected and will be the text in the "here document", in this case your input here.