如何使用Windows批处理修改数字变量值 [英] How to modify a numeric variable value with Windows batch

查看:679
本文介绍了如何使用Windows批处理修改数字变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本文件script_A.cmd,其中包含许多命令,包括以下命令:

I have a script file script_A.cmd containing a lot of commands, including the following:

set NUMBER_RUN=1

此脚本调用另一个名为stript_B.cmd的脚本. 在运行script_B.cmd的过程中,我想更新script_A.cmd并将NUMBER_RUN值的值增加1.换句话说,在第一次运行后,应更改script_A中的 text .cmd到

This script calls another script called stript_B.cmd. During the run of script_B.cmd, I want to update the script_A.cmd and increment the value of the NUMBER_RUN value by 1. In other words, after the first run, it should change that text in script_A.cmd to

set NUMBER_RUN=2

,以此类推以进行后续运行.因此,这需要批处理算法和某种搜索/替换来相应地更改script_A.cmd中的实际文本.

and so on for subsequent runs. So this requires both batch arithmetic and some kind of search/replace to change the actual text in script_A.cmd accordingly.

如何做到这一点,而无需使用从Internet下载的任何工具,而仅使用Windows本机批处理?

How do I do that, without using any tools downloaded from the internet, just Windows native batch?

推荐答案

自动更改代码是个坏主意.最好使用文件来存储值,例如:

Automatic change of code is a bad idea. Better use a file to store values, like:

script_B.cmd

<count.txt set /p Number_Run=
set /a Number_Run +=1
>count.txt echo %Number_Run%

第一行从文件中读取计数器,第二行将其加一,第三行再次将其重写到文件中.

First line reads the counter from a file, second line increases it by one, and the third line rewrites it to the file again.

script_A.cmd

<count.txt set /p Number_Run=
echo %Number_Run%

这篇关于如何使用Windows批处理修改数字变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆