How to check if an output has been spent? Using an rpc client (e.g. bitcoin-cli), for a given transaction and index of an output of it, how can I tell if the output is currently an utxo, or if it has already been spent?

In the latter case, I'd also want to know the transaction which spent it.

I looked at the gettxout command, but it isn't clear to me how to extract the answer from the data it returns.

I'm running a full node with txindex=1.
If gettxout returns something, the output is unspent. If it returns nothing, the output either never existed or is spent.

You do not need -txindex for this.