Cherry picked postcmd and precmd for tests