简体   繁体   English

将两个标准输入传递给 bash 脚本

[英]Pass two stdin to bash script

I'm executing uninstall.sh in within bash script which access two std inputs, "yes" and it executes some steps, and then another "y" for to execute another steps as confirmation.我在 bash 脚本中执行 uninstall.sh,该脚本访问两个标准输入“是”,它执行一些步骤,然后另一个“y”用于执行另一个步骤作为确认。

Tried using here doc option as below:尝试使用here doc选项,如下所示:

./uninstall.sh <<"EOF"
yes
y
EOF

or或者

./uninstall.sh <<EOF1 <<EOF2
yes
EOF1
y
EOF2

but it only accepts yes and first stdin and for seconds, it does not take "y" as input, giving below error:但它只接受是和第一个标准输入,并且在几秒钟内,它不接受“y”作为输入,给出以下错误:

java.util.NoSuchElementException: No line found java.util.NoSuchElementException:找不到行

What I'm missing here?我在这里缺少什么?

You have mentioned that you are using java.您提到您正在使用 java。 If you are using scanner.nextLine() to read both the inputs try following command如果您使用scanner.nextLine() 来读取两个输入,请尝试以下命令

printf "yes\ny" | ./uninstall.sh

If you are using scanner.next() to read both the inputs try如果您使用scanner.next() 来读取两个输入,请尝试

printf "yes y" | ./uninstall.sh

Make sure you are not closing the input stream using scanner.close() after reading the first input.确保在读取第一个输入后没有使用scanner.close()关闭输入stream。 Check if you are having same issue as https://stackoverflow.com/a/13042296/10879454检查您是否遇到与https://stackoverflow.com/a/13042296/10879454相同的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM