Subject to the provisions of section 304, the officer in charge of the prison shall, upon delivery of an order made under sub-section (1) of section 302 and duly countersigned, where necessary, under sub-section (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 examined or until the Court authorises him to be taken back to the prison in which he was confined or detained.