1

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"
5
  • the thing is. I cannot edit the source code of this Java application. I only got the jar.
    – Henkes
    Jun 23, 2015 at 8:30
  • 1
    What the answer in the linked duplicate tells you (you did read it?) is that you just pass the arguments as normally, like any other command. Jun 23, 2015 at 8:31
  • Yes, I have tried this. java -jar myscript.jar argument1 argument2 argument3 argument4 (also with and without \n in the end. but the result is the same. the application is still waiting for input
    – Henkes
    Jun 23, 2015 at 8:38
  • Ah, then your question is not about "arguments", but about normal input. I'll post an answer. Jun 23, 2015 at 8:41
  • You have a point there, the word arguments is a bit confusing here. will edit the question
    – Henkes
    Jun 23, 2015 at 8:43

1 Answer 1

1

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.

1
  • How to specify value for password string. I mean for inputs when console.readPassword() is called.
    – Ana
    Nov 1, 2017 at 8:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.