To redirect output from a system command, you can use the > operator.
In UNIX:
commandname 1> /path/to/file 2>&1
This will redirect both errors and output to file.
Or, the program you run may have a switch to redirect output to a file. such as:
commandname -o /path/to/file
In Windows, I believe you can just use:
'commandname > \path\to\file'
Please correct me if I am wrong.