The officer in charge of a prison shall receive and detain all persons duly committed to his custody, under this Act or otherwise, by any Court, according to the exigency of any writ, warrant or order by which such person has been committed, or until such person is discharged or removed in due course of law.