You can not; instead, the hidden buffer must be (temporarily) activated to execute commands on it.
(The only exceptions are the getbufline() and get/setbufvar() functions, but you cannot handle them.)
My ingo-library plugin provides a convenient ingo#buffer#visible#Execute( bufnr, command ) function that handles this for you.
Ingo karkat
source share