【问题标题】:Ask for user input and replace values using a batch file使用批处理文件请求用户输入和替换值
【发布时间】:2020-05-21 05:53:48
【问题描述】:

在 Windows 批处理文件中,我想询问用户输入,例如:“你叫什么名字:jack”,然后替换 newname 与用户输入的内容 jack

旧文件内容

first newname
second newname
oldfile/newname/
available/newname
newname

新文件内容

first jack
second jack
oldfile/jack/
available/jack
jack

【问题讨论】:

标签: batch-file command-line


【解决方案1】:

首先我使用了变量

title Variables
set newinput=Default
echo Name of new Database:
set /p newinput=

然后用变量替换旧数据:

first %newinput%
second %newinput%
oldfile/%newinput%/
available/%newinput%
%newinput%

然后使用用户输入的内容创建一个新文件:

@echo off
title Variables
set newinput=Default
echo Name of new Database:
set /p newinput=
break>test.sh
@echo first %newinput%>> test.sh
@echo second %newinput%>> test.sh
@echo oldfile/%newinput%/'>> test.sh
@echo available/%newinput%>> test.sh
@echo %newinput%>> test.sh

每次运行批处理文件并且用户输入内容时,它都会更改文件。

【讨论】:

  • 我很确定你在这里添加了一个不需要的前导空格字符:set newinput= Default
猜你喜欢
  • 2015-01-14
  • 2010-09-19
  • 1970-01-01
  • 2021-12-27
  • 2015-10-27
  • 1970-01-01
  • 2018-04-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多