首页 文章

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

提问于
浏览
-1

我已经创建了这个代码,当我输入一些文本到 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

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

    @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 环境变量混淆!

相关问题