通过批处理文件将用户输入保存到文本文件中

时间:2018-12-09 18:22:10

标签: batch-file user-input

我已经创建了这段代码,当我在usernameyearsoflife中键入要在.txt file中导出的文本时,我无法这样做。

@echo off
color 0a
echo.
echo.
echo    Please insert the following
echo.
echo.
echo.
set /p username=name:
set /p yearsoflife=age:
%username% > name.txt
%yearsoflife% > yourage.txt

1 个答案:

答案 0 :(得分:0)

这是一种可能的解决方案:

@echo off
color 0a
echo.
echo.
echo    Please insert the following
echo.
echo.
echo.
set /p _username=name: 
set /p yearsoflife=age: 
(echo=%_username%) > name.txt
(echo=%yearsoflife%) > yourage.txt

您的问题不清楚。您提到要在一个文本文件中同时包含两个变量内容。因此,您可以尝试(将>符号加倍):

@echo off
color 0a
echo.
echo.
echo    Please insert the following
echo.
echo.
echo.
set /p _username=name: 
set /p yearsoflife=age: 
(echo=%_username%) >> your_name.txt
(echo=%yearsoflife%) >> your_name.txt

注意:更改set /p username=name:行只是为了不将此username变量与username环境变量混淆!

相关问题