我需要创建一个.bat文件,该文件在命令提示符下获取用户输入并将其保存到文本文件中。
在命令提示符下,它想:
What is the path: "C:\Users\21241\Desktop\test"
Number of times to run: "7"
在文本文件中,它看起来像:
User_input_Path: C:\Users\21241\Desktop\test
Num_run_time: 7
无论如何要做到这一点?
答案 0 :(得分:3)
@echo off&cls
set /p $path=What is the path:
set /p $num=Number of times to run:
(echo User_input_Path: %$path%
echo Num_run_time: %$num%)>your_text_file.txt
答案 1 :(得分:0)
SET /P pat=What is the path:
SET /P num=Number of times to run:
echo User_input_Path: %pat% > txt.txt
echo Num_run_time: %num% > txt.txt
不在Windows上,所以无法测试,但这应该可行。
答案 2 :(得分:0)
假设您只想运行一次:
@echo off
SET /P Path="What is the path: "
SET /P Num="Number of times to run: "
ECHO What is the path: %Path% > sample.txt
ECHO Number of times to run: %Num% > sample.txt
但是,如果您希望“运行次数”为用户输入路径的次数,则:
@echo off
SET /P Num="Number of times to run: "
SET Count=1
IF %Num% NEQ %Count% (
SET /P Path="What is the path: "
ECHO What is the path: %Path% > sample.txt
SET /A Count=Count+1
) ELSE exit