jon077
jon077

Reputation: 10449

How do I redirect stdin from a shell script to a command in the shell script?

How do I redirect stdin from a shell script to a command in the shell script? I am trying to pass the stdin to a java System.in stream.

I want to replace

find . -type f | $JAVA_HOME/bin/java com.domain.BatchProcess

with

 find . -type f | ./batch.sh

Upvotes: 6

Views: 5322

Answers (3)

Jeremy Cantrell
Jeremy Cantrell

Reputation: 27416

If the command:

$JAVA_HOME/bin/java com.domain.BatchProcess

is expecting input from stdin, then putting it in a script and running your second command will work.

Upvotes: 4

jon077
jon077

Reputation: 10449

It does it automatically.

Upvotes: 1

Dave Stenglein
Dave Stenglein

Reputation: 1420

If you exec the command within the script, it will replace the shell and inherit it's file descriptors, including stdin,stdout and stderr.

Upvotes: 8

Related Questions