@EXECSTR[[n,]command] : Runs the specified command and returns line n (or the first line if n is not specified) written to stdout by command. For example, to return the third line returned by VER /R:

 

    echo %@execstr[2,ver /r]

 

If n is negative, @EXECSTR starts at the last line and counts backwards.

 

@EXECSTR is useful for retrieving a result from an external utility. For example, if you have an external utility called NETTIME.EXE which retrieves the time of day from your network server and writes it to standard output, you could save it in an environment variable using a command like this:

 

set server_time=%@execstr[d:\path\nettime.exe]

 

If the same utility returned a result properly formatted for the TIME command, you could also use it to set the time on your system:

 

time %@execstr[d:\path\nettime.exe]

 

@EXECSTR can also be used with internal commands:

 

echo Newest file is: %@execstr[*dir /a:-d /h /o:-d /f]

 

@EXECSTR involves several extensive internal processing stages. You might be able to use more complex command sequences (pipes, command groups, etc.) as its parameter, but always test carefully first as the results may not always be what you expect. We recommend that you only use a single command (internal, external, batch file, etc.) parameter.

 

See also: _EXECSTR, @EXEC and @EXECARRAY.