Completely rewrite the print_cmd_output using
Don't use popen as it is unsafe. It launches a shell and leaves it vulnerable to all kinds of attacks,
if user input is not strictly filtered.
This version should be safe and faster