Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
batnoob
- Posts: 56
- Joined: 19 Apr 2017 12:23
#1
Post
by batnoob » 19 Apr 2017 12:29
What is wrong with my code?
I want it to make a spinner, it is supposed to type a character backspace it, then type the next character, and so on. what it does instead is echo "- \ | /" over and over again
Code: Select all
@echo off
setlocal EnableDelayedExpansion
::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=$BS" &set "$Details=Create $ESC Ascii-0x1B-27, Expansion insensitive"
::
::(
for /f "delims=#" %%a in (
'"prompt #$H# &echo on &for %%b in (1) do rem"'
) do (
set "%$Defines%=%%a"
set "%$Defines%=!$BS:~0,1!"
)
set "s1=-"
set "s2=\"
set "s3=^|"
set "s4=/"
:spinner
echo %s1% %$BS% %s2% %$BS% %s3% %$BS% %s4% %$BS%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
FOR %%a IN (1,5,10) DO (call :spinner)
Last edited by
batnoob on 19 Apr 2017 13:20, edited 1 time in total.
-
Aacini
- Expert
- Posts: 1914
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#2
Post
by Aacini » 19 Apr 2017 12:42
batnoob wrote:What is wrong with my code?
That you have not included a single explanation of what it supposeddly should do and, in case you have any problem with it, a clear description of what is the problem perhaps?
I suggest you to carefully read
this post that, BTW, is placed at the very beginning of this forum!
Antonio
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#3
Post
by aGerman » 19 Apr 2017 13:35
ECHO won't work here because it always writes a new line.
Code: Select all
@echo off
for /f %%a in ('"prompt $H &for %%b in (1) do rem"') do set "BS=%%a"
for /l %%i in () do for %%j in (^| / - \) do (
<nul set /p "=%BS%%%j"
>nul ping -n 1 localhost
)
Steffen
-
batnoob
- Posts: 56
- Joined: 19 Apr 2017 12:23
#4
Post
by batnoob » 19 Apr 2017 13:38
Thank you, it works perfect!
-
batnoob
- Posts: 56
- Joined: 19 Apr 2017 12:23
#5
Post
by batnoob » 19 Apr 2017 13:46
how to place that at the end of a line?
(e.g.
Code: Select all
set var=call:spinner
:spinner -- Spins
for /f %%a in ('"prompt $H &for %%b in (1) do rem"') do set "BS=%%a"
for /l %%i in () do for %%j in (^| / - \) do (
<nul set /p "=%BS%%%j"
>nul ping -n 1 localhost
)
GOTO:EOF
echo. %var%
)
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#6
Post
by aGerman » 19 Apr 2017 14:10
As I told you - ECHO won't work.
Code: Select all
@echo off
for /f %%a in ('"prompt $H &for %%b in (1) do rem"') do set "BS=%%a"
<nul set /p "=Loading "
for /l %%i in (1 1 50) do for %%j in (^| / - \) do (
<nul set /p "=%BS%%%j"
>nul ping -n 1 localhost
)
echo(
pause
Steffen
-
batnoob
- Posts: 56
- Joined: 19 Apr 2017 12:23
#7
Post
by batnoob » 19 Apr 2017 14:20
Sorry, I don't know how to print any thing to the screen other than with echo (I'm a noob)
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#8
Post
by aGerman » 19 Apr 2017 14:23
With the SET /P trick, as you can see