一个例子...

@echo off
setlocal
set /p "_myvar=what is your name?"
echo HELLO!>file.txt
echo %_myvar%!>>file.txt
echo done!
pause
type file.txt
endlocal
exit

现在 file.txt 看起来像:

HELLO!
John Smith!

(假设你输入 John Smith 作为你的名字。)

现在你的批处理文件的控制台如下所示:

what is your name?John Smith
done!
Press any key to continue...
HELLO!
John Smith!

(它应该快速退出,以至于你可能无法在提示后看到任何内容)