This question already has an answer here:
Bash how do you capture stderr to a variable?
I would like to do something like this inside of my bash script
sh -c path/myExcecutable-bin 2>&1 =MYVARIABLE
How do you send stderror output to a variable ?
Tim Pote
To save both stdout and stderr to a variable:
MYVARIABLE="$(path/myExcecutable-bin 2>&1)"
Note that this interleaves stdout and stderr into the same variable.
To save just stderr to a variable:
MYVARIABLE="$(path/myExcecutable-bin 2>&1 > /dev/null)"
来源:https://stackoverflow.com/questions/11087499/bash-how-do-you-capture-stderr-to-a-variable