If the person to whom the writ is directed refuses after service to obey the same, the court, upon affidavit, shall issue an attachment against such person, directed to any officer, commanding him forthwith to apprehend such person and bring him immediately before such court or judge; and upon being so brought, he shall be committed to jail until he makes due return to such writ, or is otherwise legally discharged.