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"
Community
  • 1
  • 1
Henkes
  • 288
  • 4
  • 16
  • the thing is. I cannot edit the source code of this Java application. I only got the jar. – Henkes Jun 23 '15 at 08: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. – Some programmer dude Jun 23 '15 at 08: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 '15 at 08:38
  • Ah, then your question is ***not*** about "arguments", but about normal input. I'll post an answer. – Some programmer dude Jun 23 '15 at 08:41
  • You have a point there, the word arguments is a bit confusing here. will edit the question – Henkes Jun 23 '15 at 08:43

1 Answers1

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.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • How to specify value for password string. I mean for inputs when console.readPassword() is called. – Ana Nov 01 '17 at 08:06