When any person against whom an indictment has been filed is in prison for any other cause, the court may, by order in writing, without writ of habeas corpus , direct the gaoler to bring up the body of such person as often as is required for the purposes of the trial, and the gaoler shall obey such order.