如何将stdin从shell脚本重定向到shell脚本中的命令?

时间:2022-06-29 14:40:01

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.

如何将stdin从shell脚本重定向到shell脚本中的命令?我试图将stdin传递给java System.in流。

I want to replace

我想替换

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

with

 find . -type f | ./batch.sh

3 个解决方案

#1


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.

期待来自stdin的输入,然后将其放入脚本中并运行第二个命令将起作用。

#2


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

如果在脚本中执行命令,它将替换shell并继承它的文件描述符,包括stdin,stdout和stderr。

#3


It does it automatically.

它自动完成。

#1


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.

期待来自stdin的输入,然后将其放入脚本中并运行第二个命令将起作用。

#2


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

如果在脚本中执行命令,它将替换shell并继承它的文件描述符,包括stdin,stdout和stderr。

#3


It does it automatically.

它自动完成。