Moved external program execution to a function.
Added a function that uses popen for executing commands.