Another way to do it, if you don't want to create too much code is to use > in the shell command to dump it to a file. E.g. ls > ls.out