How to capture the output from a shell command

Submitted by: Clay Helberg Last Updated: 2006-08-03

A utility function which executes a shell command and returns its output

function windows_command(command) { local result = system("cmd /C " . command . " > $home\epicoutput.txt", 1); if (result != 0) { return "*** command failed ***"; } else { local output = ""; local outputfile = open("$home\epicoutput.txt"); local line; while (getline(outputfile, line) != 0) { output = output. line; }   close(outputfile); system("cmd /C del $home\epicoutput.txt",1); return output; } }
 * 1) executes the given command and returns any text sent to stdout