Fix pyflakes check for Python 3, wrap error while running cmd in proper class: unicode for 2 and str for 3.