Replaced Popen with check_output