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"
If you want to redirect the normal standard input of the program, you could use so called "here documents" (see eg the BASH manual page ):
java -jar script.jar <<EOF
your input here
EOF
That means standard input (aka stdin
) is redirected and will be the text in the "here document", in this case your input here
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.