use spawn function instead of Popen