dos assign command output to variable (when output is of multiple lines)

REM This example demonstrates how to assign the output of the DOS command to a variable in BASIC.
CLS
SHELL "DIR > temp.txt"
OPEN "temp.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
    LINE INPUT #1, line$
    PRINT line$
LOOP
CLOSE #1
KILL "temp.txt"
END