Subject to the provisions of section 269, the officer incharge of the prison shall, upon delivery of an order made under Sub-section (1) of' section 267 and duly Countersigned, where necessary, under subsection (2) thereof, cause the person named in the order to be taken to the court in which his attendance is required, so as to be present there at the time mentioned in the order and shall cause him to be kept in custody in or near the court until he has been examine or until the court authorizes him to be taken back to the prison in which he was confined or detained.