How to capture plantuml.jar output in shell?

0 votes
asked Nov 27 in Question / help by mawi (380 points)

I want to capture the output of plantuml.jar running, to for example save it, reformat it (indent, etc) or similar. So, I want to:

* run java -jar plantuml.jar -v [etc...] and capture the output in a shell variable, for instance. It should not be printed to the console.

But I cannot get it to behave nicely as other commandline tools ;-)

In bash, this works for most all commands you can think of:

foo=$(cat test.txt); echo "Need to write this first..."; echo $foo

So, I want this to work:

foo=$(java -jar ./plantuml.jar -v -tpng -charset UTF-8 -o ./testimage.png ./src/nkp/test.puml); echo "Not yet"; sleep 1; echo $foo

But it does not.

Any errors i am doing? Solutions? Workarounds?

BR! /mawi

commented Nov 28 by albert (2,580 points)
Might it be that the errors go to `stderr` and you are only catching `stdout`?
commented Nov 28 by mawi (380 points)

Solved! Thanks for your reply Albert! That was it!

What a rookie mistake! Lol! I can't believe I did not consider that. I had already routed stderr to stdout in my script, but... oh well... there it is! Thanks again.

For any readers benefit, here is the working bash line, to in this example indent the plantuml output (which is what I was after for my logging):

foo=$(2>&1 java -jar ./plantuml.jar -v -tpng -charset UTF-8 -o ./testimage.png ./src/nkp/test.puml); echo "$foo" | sed 's/^/    /'

Thanks again Albert.

And as always, thanks to the plantuml team for an awesome tool! :)

BR! /mawi

PS
of course to just indent, you can just pipe and not use a variable "in between", so:

2>&1 java -jar ./plantuml.jar -v -tpng -charset UTF-8 -o ./testimage.png ./src/nkp/test.puml | sed 's/^/    /'

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...