fix issue using popen in python 2.4, optimize code