The officer in--charge of a prison shall forthwith, after the execution of every such writ, warrant or order as aforesaid, other than a warrant of commitment for trial or after discharge of the person committed thereby, return such writ, warrant or order to the court by which the same was issued or made together with a certificate, endorsed thereon and signed by him showing how the same has been executed or why the person committed thereby has been discharged from custody before execution thereof.