Section 267(1)(b) in The Code of Criminal Procedure, 1973
(b)that it is necessary for the ends of justice to examine such person as a witness, the Court may make an order requiring the officer in charge of the prison to produce such person before the Court for answering to the charge or for the purpose of such proceeding or, as the case may be, for giving evidence.