refactor run_cmd. don't use tempfiles