0

I need to be able to change the title of batch A at the same time of execution of other parts of script.

i want to be able to have it say Hello! world. and echo 1&2 simutaneously and while the screen is switching between 1 and 2 i need the title to change from 2 to 3.

and please dont give me something like this.

echo Hello! world.
ping localhost 3 >nul
title 2
echo Hello! world. 1
ping localhost 3 >nul
title 3
echo Hello! world. 2
ping localhost 3 >nul
title 2
:loop

Thanks in advance to anyone with an answer that works!

4

2 回答 2

1

You can't do that in pure Batch. Batch is a procedural language.

You could try writing a program in another language that can talk to the Windows API: http://msdn.microsoft.com/en-gb/library/windows/desktop/ms682073(v=vs.85).aspx

You might be able to spawn a separate process that could get the Handle for your Console window and then change the title remotely.

于 2013-02-12T22:22:01.033 回答
0

This can be done with pure batch.
You only need a second thread, that can be started with start /b.

The expample code updates the current time in the title until the user press enter.

@echo off
REM *** Trampoline to call a label included in the filename
FOR /F "tokens=3 delims=:" %%L in ("%~0") DO goto :%%L

start "" /b cmd /c %~d0\:change_title:\..\%~pnx0

2> lock.tmp (
set /p "value=Enter Text: "
)

echo End of prog
exit /b

:change_title
2> NUL ( > lock.tmp ( break ) ) || (
    title Current time %time%
    ping localhost -n 2 > NUL
    goto :change_title
)

del lock.tmp
title Thread finished
exit /b
于 2020-03-12T11:25:09.687 回答