The judge before whom the writ is returned, after hearing the matter, both upon the return and any other evidence, shall either discharge or remand the petitioner, admit the prisoner to bail, or make such order as may be proper. He or she shall adjudge the costs of the proceeding, including the charge for transporting the prisoner, to be paid as shall seem right. The payment may be enforced by attachment or otherwise by the court to which the proceedings are returned.