Using popen instead of system