Here's how to write expressions for the values that you want. Then it is straightforward to write the values of these expressions to a text file using print or printf.
1. After solving, the number of nodes explored is reported by CPLEX in a short message like this:
CPLEX 20.1.0.0: optimal integer solution; objective 235625
308 MIP simplex iterations
50 branch-and-bound nodesThis message is also stored in the built-in parameter solve_message. You can use the following expression to extract the number of nodes from solve_message:
num0(substr(solve_message,match(solve_message,"s\n")+2))2. Tell CPLEX to return gap values, by setting
option cplex_options 'return_mipgap=3';(or if you are already setting a cplex_options string, by adding return_mipgap=3 to it). Then the relative and absolute mip gaps will be returned in the expressions <obj>.relmipgap and <obj>.absmipgap -- where you replace <obj> by the actual name of your objective function.
3. You will need to solve again with nodelim=0 added to the above cplex_options string, to get the gap values at the end of the root node processing.