-3

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

set NUMBER_RUN=1

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

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.

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

3
  • 5
    so many duplicates: Calculating the sum of two variables in a batch script, Math on batch... Commented Nov 14, 2016 at 16:52
  • 1
    You understand that variable values don't reside in the batch but in the currently active environment. IF you do set fix values you are overwriting the current value. You might look at help set especially Set /A += Commented Nov 14, 2016 at 17:39
  • or google "how to do arithmetic in batch" Commented Nov 15, 2016 at 3:22

1 Answer 1

1

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

script_B.cmd (reading the number from the file, incrementing it and writing it back)

<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 (just read the counter from the file)

<count.txt set /p Number_Run=
echo %Number_Run%
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.