The PHP documentation specifies that the exec()
function can have from one to three parameters:
string exec ( string $command [, array &$output [, int &$return_var ]] )
Surely now you are calling it with just one (the command), but you would be interested in passing it a second parameter (output). This second parameter returns an array with the command output (line by line).
From the documentation linked above (my translation):
output
If the output argument is present, then the specified array will be filled with each line of the command output. The blanks at the end, as well as \ n, are not included in this array. Note that if the array contains elements, exec () will add to the end of the array. If you do not want the function to add elements to the array, call unset () in the array before passing it to exec ().
Then, you only have to go through the second parameter to see the result of the operation performed with exec()
and save it in a file.
If you want to do it without PHP, and you can add something at the end of the command, you could do something like this:
$miComando .= " > fichero.txt";
This will cause the string "> file.txt" to be added to the end of your command, which in cmd and shell will write the result in a txt file for you.