better method for getting output, fixed compatibility with linux