You can't. Usually you can achieve this kind of thing by including a carriage-return character (0x0D) in the file which will put the cursor back to the first column in the same line. But in this case it doesn't work; the CR is just silently eaten.
Furthermore getting the CR in there is kinda tricky and at least here involved a text editor. I'd suggest you write a little utility program that will do this for you, it actually isn't very hard. The following little C program might suffice (if you don't need Unicode):
#include <stdio.h>
int main(int argc, char* argv[]) {
if (argc < 2) return 1;
printf("\r%s", argv[1]);
}
It does nothing more than printing a CR character and then the text you specify as its first argument. Usage as follows:
@echo off
<nul set /P X=Step 1
pause>nul 2>nul
over.exe "Step 2"
The last line is the call to that program. The second line is the normal batch idiom for printing text without a trailing line break (which is important in this case because otherwise you couldn't overwrite the line). You could just as well use the program above as well in that place, though.
A lightly hacky way, but the only one where you can be sure where you end up, would be to use cls prior to your step output. Will flicker but that way you always write to the upper-left. And clobber everything that was visible in the console (which is why I wouldn't recommend it); most users don't like that too much.
2For me, this just prints "Step 1Step 2" instead of having just "Step 2" on the screen. – galmok – 2016-06-07T11:34:30.210
@galmok This has begun to happen to me too, but I'm sure it never used to (as I have a script that used to work perfectly put recently has changed to the behaviour you describe.) It appears that the
setcommand now strips any CR and LF characters (as well as spaces) after the=. Try putting a non-whitespace character between the=and the!ACSII_13!– timfoden – 2017-04-26T06:28:30.437There is a way to do all of this... I actually came to look to see if anyone else has noticed, because I Wanted to see if they had discovered how far it went. ... Can I write up an ANSWER on stack overflow? OR.. like a Question and immediately answer it? I suppose I could write it in question form about what you could do with it.. I've got to go eat something but I'll update this with a link for you. – Brent Rittenhouse – 2019-02-19T20:06:34.473
Write !ASCII_13! after Step 1 to prevent stripping, so in step 2 you would code:
set /p "=Step 2 " <NUL– Zimba – 2019-12-21T14:09:13.857