I want to send the stdout and stderr of terminal while I run a huge batch file. The batch file
echoer.sh
echo $HOME
sleep 3
echo $HOME
sleep 3
echo $HOME
# n times
Executing in terminal
./echoer.sh | redis-cli -x publish echoer
This waits for the entire execution of echoer.sh
to finish and then send the publish command. Is there a way to publish the output as soon as you receive it?
Current Output
# command
redis-cli subscribe echoer
# output below
1) "message"
2) "echoer"
3)"/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn
2
Answers
Sure, read the output of your script one line at a time and then publish that line to Redis:
Using
xargs
, it sends each line toechoer
channel using xargs utility.