重定向应用程序(JAVA)的输入,但仍允许在标准输入BASH [英] Redirecting input of application (java) but still allowing stdin in BASH
问题描述
我有点困惑,我有这个工作的昨天,但它只是停止接受重定向的标准输入,几乎是神奇。
I'm a little confused, I had this working yesterday, but it just stopped accepting the redirected stdin, almost magically.
set -m
mkfifo inputfifo
mkfifo inputfifo_helper
((while true; do cat inputfifo; done) > inputfifo_helper)&
trap "rm -f inputfifo inputfifo_helper java.pid; kill $!" EXIT
exec 3<&0
(cat <&3 > inputfifo)&
NOW=$(date +"%b-%d-%y-%T")
if ! [ -d "logs" ]; then
mkdir logs
fi
if [ -f "server.log" ]; then
mv server.log logs/server-$NOW.log
fi
java <inputfifo_helper -jar $SERVER_FILE & echo $! > java.pid && fg
这是运行良好,我可以附和事情inputfifo和应用得到了它,并把它的控制台,以及我可以直接键入。它甚至可以通过屏幕上的工作。绝对没有code-明智的改变,但重定向标准输入已停止工作。我试图改变的文件描述符9,甚至是127,但是没有固定它。
This was running fine, I could echo things to inputfifo and the app got it, and I could type directly into it's console as well. It even worked through screen. Absolutely nothing code-wise has changed, but the redirected stdin has stopped working. I tried changing the file descriptor to 9, or even 127, but neither fixed it.
我是不是忘了什么东西?有没有它打破了一个具体的理由,不再工作?
Am I forgetting something? Is there a specific reason it broke and no longer works?
(我使用的,而不是发送输入到屏幕本身,因为我开始屏幕分离,并拒绝,除非它被连接到ATLEAST一旦接收输入这个,我不知道这是否是一个错误或预期)
(I'm using this instead of sending input to the screen itself because I start the screen detached and it refuses to receive input unless it's been attached to atleast once, I don't know if this is a bug or intended)
推荐答案
如果你能保持你的java程序后台运行,您可以尝试从控制终端的/ dev / tty的$ C $读C>,写使用而读循环inputfifo。
If you can keep your java program backgrounded, you may try to read from the controlling terminal /dev/tty
and write to inputfifo using a while-read loop.
# ...
java <inputfifo_helper -jar $SERVER_FILE & echo $! > java.pid
while IFS="" read -e -r -d $'\n' -p 'input> ' line; do
printf '%s\n' "${line}"
done </dev/tty >inputfifo
这篇关于重定向应用程序(JAVA)的输入,但仍允许在标准输入BASH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!