Reputation: 1272
I have a Java program which I'd like to call inside a linux shell script. The Java program takes a user input from the command line.
I read somewhere that I can use echo to mimic user input as follows:
java myProgram
echo 1000
echo
However this doesn't work for me, the program is still waiting for the user input. Is there something I'm doing wrong? I can't imagine this is a difficult task.
Upvotes: 0
Views: 107
Reputation: 279940
I think you should find the process id of your java process and then write to its /proc
directory.
Say the id of the Java process is 4321
, then output to
/proc/4321/fd/0
Upvotes: 0
Reputation: 159754
Why not just pass in the value as an argument
java myProgram 1000
Upvotes: 1
Reputation: 1465
You can use echo
, but in a pipeline.
echo 1000 | java myProgram
If you want to send a file, you can use cat
:
cat file.txt | java myProgram
Upvotes: 2