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
Redirection is a feature in Linux such that when executing a command, you can change the standard input/output devices. The basic workflow of any Linux command is that it takes an input and give an output. The standard input (stdin) device is the keyboard. The standard output (stdout) device is the screen.
stdin − It stands for standard input, and is used for taking text as an input. stdout − It stands for standard output, and is used to text output of any command you type in the terminal, and then that output is stored in the stdout stream. stderr − It stands for standard error.
The pipe (" | ") symbol in the middle tells the shell to connect commandA 's standard output to commandB 's standard input before launching them.
If you exec the command within the script, it will replace the shell and inherit it's file descriptors, including stdin,stdout and stderr.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With