Reputation: 95
Apologize if this is a really simple question, but I couldn't find anything on google for "redirect stdout and stderr to bash script" and "redirect bash script output to another bash script".
I know this will redirect stdout and stderr to log.txt
, but I'm not sure how to redirect it to a bash script.
java -jar build/libs/bot-kt-1.1.3.jar > log.txt 2>&1
Ideally something that behaves like above and is like so
java -jar build/libs/bot-kt-1.1.3.jar > "./script.sh" 2>&1 # script.sh uses the $1 argument for input
Upvotes: 2
Views: 556
Reputation: 98118
You can use xargs to move data from a pipe into an argument:
java -jar build/libs/bot-kt-1.1.3.jar 2>&1 | xargs ./script.sh
to pass everything as a single argument:
java -jar build/libs/bot-kt-1.1.3.jar 2>&1 | xargs --null ./script.sh
Upvotes: 1
Reputation: 17422
You can use command substitution for that:
./script.sh $(java -jar build/libs/bot-kt-1.1.3.jar 2>&1)
In addition to perreal's answer, if your script could be changed to read from stdin instead of expecting a parameter, you could also use a pipe:
java -jar build/libs/bot-kt-1.1.3.jar 2>&1 | ./script.sh
Upvotes: 0