Here is a bit of my batch Loading script
Echo Loading
Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
Echo ºÛ º
Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ping localhost -n 2 > nul
cls
Echo Loading
Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
Echo ºÛÛ º
Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ping localhost -n 2 > nul
cls
Echo Loading
Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
Echo ºÛÛÛ º
Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
exit
Using the cls code to wipe the screen makes the screen look like a "Blink". Is there a better way to clear the screen for this batch file? TIA
Just far from perfect less glitching option: Instead of repaint the full screen, repaint only the loading line (but this has to be last painted line in the screen).
The basic idea is to ouput the line ending with a carriage return but without a line feed so the cursor is moved to the start of the line to write again over the same line.
#echo off
setlocal enableextensions enabledelayedexpansion
Rem Get a carriage return character
set "CR=" & for /f %%a in ('copy /Z "%~f0" nul') do if not defined CR set "CR=%%a"
rem The progress bar
set "fill=[##########]"
cls
echo(:: computers were created to give humans time to think while waiting ....
rem For each character in the fill
for /l %%a in (2 1 11) do (
rem Calculate the right part of the bar
set "spaces=!fill:~%%a!"
rem Output the left and right parts of the bar and carriage return
<nul set/p ".=:: Loading something big !fill:~0,%%a!!spaces:#= !!CR!"
rem Pause for a second
ping -n 2 "" > nul
)
echo(
echo(:: Done
If you can not change your code/design so the last line is the only one repainted, at least try to enclose the painting operation inside a block (code enclosed in parenthesis) so in each paint operation commands are only parsed once, and prepare everything before starting to paint. It will not avoid the glitches, but will be less evident
#echo off
setlocal enableextensions enabledelayedexpansion
for /l %%a in (0 10 100) do (
call :loadingScreen %%a
>nul ping -n 2 ""
)
echo(:: Done
goto :eof
:loadingScreen percent
setlocal enableextensions enabledelayedexpansion
rem Prepare everything
set "sb=+----------+"
set "fill=^|##########^|"
set "eb=+----------+"
set /a "chars=2+%~1/10"
set "spaces=!fill:~%chars%!"
set "loadBar=!fill:~0,%chars%!!spaces:#= !"
rem Time to paint
( cls
echo(:: computers were created to give humans time to think while waiting .... %time%
echo(
echo( %sb%
echo( Loading something big %loadBar%
echo( %eb%
echo(
)
goto :eof
Related
im currently making something along the lines of a sentence generator, it uses text files which have a list of words in them, for example celebrity.txt has a list of celebrities and this script both shuffles the text file into newcelebrity.txt and takes the first one from that list so its different every time, and ive run into a problem, i want it to be one line and that you can call a variable in the sentance youre typing, not break it down as it is right now, is there a way to have it "this $celebrity is really great" as of now, it works like this: https://gyazo.com/9ae8583ed5457709bd1c1dc9cc0cc106 and outputs as this https://gyazo.com/1a5a90f1fbf80faa73d71791a8c1c761, i dont mind the quotation marks at all, its just the way you input it.
Is there any way to make it work like i want it to or is this a limitation of batch files?
set /p message=Unity:
set /p input=The variable:
set /p after=Unity:
:gen
setlocal
cd ..
cd rcs
echo doing background work, please wait a few seconds :)
for /f "delims=" %%a in (%input%.txt) do call set "$$%%random%%=%%a"
(for /f "tokens=1,* delims==" %%a in ('set $$') do echo(%%b)>new%input%.txt
endlocal
cls
set "File=C:\Users\%USERNAME%\Desktop\gg\rcs\new%input%.txt"
set /a count=0
echo background work done :)
timeout /t 1 >nul
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%File%"') do (
Set /a count+=1
Set "output[!count!]=%%a"
)
For /L %%i in (1,1,%Count%) Do (
Call :Action "!output[%%i]!"
pause
)
Exit
::*******************************************************
:Action
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo %message% %1 %after%
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo if you want to go back and change your inputs type back
echo if you want to continue generating, type gen
echo.
set /p instruction=
goto %instruction%
::*******************************************************
To get rid of the quotation marks, just use %~1 instead of %1.
I'm assuming, you want to input something like 'this $celeb is great' instead of the first three set /p lines (as your output is already in one line).
I used some fixed variables to keep it short - of course you would fetch them from the user and the text file instead, as you already did.
#echo off
setlocal EnableDelayedExpansion
set "count=3"
set "output[3]=John"
set "sentence=this $celeb is great."
REM above would be your 'set /p' instead
call :action "!output[%count%]!"
goto :of
:action
echo !sentence:$celeb=%~1!
(just to be clear: $celeb is not a variable - it's just a string, that we replace later, so from user's perspective, it behaves like a variable)
I created my first batch file ever a couple of weeks ago to use livestreamer more comfortably.
Basically I can either type in the name of Twitch streamer or I can start something from another plattform.
What I am trying to do is is save my input as an option for the next time.
Let's say I went to the twitch stream of "shroud". When the stream ends I would like to put shroud as an option in the beginning of the script:
:start
title twitchings
color 0a
echo Select [#] or enter Stream
echo.
echo 1. non twitch
echo 2. shroud
set /p select=?
I assume it would be easiest to store that list in a txt file and then load it upon running the batch file, but my basically non-existant knowledge in coding hinders me from creating it.
Does anyone know a quick help, I would also love to know if there is a website where I can learn this stuff without googling for hours :)
This is my updated script for those who are searching for the same issue.
#ECHO off
:start
title twitchings
color 0a
echo Select [#] or enter Stream
echo.
echo 1. non twitch
setlocal enableextensions enabledelayedexpansion
set "file=C:\Users\[...]\savedstreams.txt"
set /A i=1
for /F "usebackq delims=" %%a in ("%file%") do (
set /a i += 1
echo !i! . %%a
)
set /p select=?
set /a varCheck=%select%
if %varCheck% == %select% (goto :isnumber) else (goto :isstream)
exit /B
:isnumber
set "lineNr=%select%"
set /a lineNr-=1+1
for /f "usebackq delims=" %%a in (`more +%lineNr% savedstreams.txt`) DO (
set "stream=%%a"
goto :leave
)
:leave
set "stream=%stream:*:=%"
echo stream: %stream%
goto qual
:isstream
set "stream=%select%"
echo %stream% >>savedstreams.txt
goto qual
:TpyeInSource
echo enter URL
echo.
set /p select2=?
livestreamer %select2%
GOTO end
:qual
livestreamer http://twitch.tv/%stream% 1080p60 || livestreamer http://twitch.tv/%stream% best
GOTO end
:end
#CHOICE /C:rqn /M "[R]etry, [Q]uit or [N]ew"
IF ERRORLEVEL 3 GOTO start
IF ERRORLEVEL 2 GOTO quit
IF ERRORLEVEL 1 GOTO qual
GOTO quit
:quit
echo "bye."
#PAUSE
Thank you guys!
You can use >> to put the output of a command in text file. For example:
echo hi everyone >>textfile.txt
will add "hi everyone" to the last line of the text file.
You can also use > to add it to the first line instead.
Below is what I have tried already. If possible, I'd also like to make it happen slowly enough for the progress bar updates to be apparent, instead of just jumping to 100%, but quick enough that the update commands aren't apparent in the output
color 0a
%n=0
:start
if /L %n <100 (
%n+1=%n
title %n
goto start
)
else (
go to end
)
:end
echo finished
I recieved this error, I don't understand what it's saying and why it doesn't work. Note that I wrote this in notepad and ran this as a batch file on windows.
Here's an example to get you motivated.
#Echo Off
SetLocal EnableDelayedExpansion
Set "bar="
For /L %%a In (1,1,48) Do Set "bar=!bar!>"
Set "n=0"
For /L %%a In (1,1,23) Do Set/A n+=1
Set "i=0"
Echo( Processing files:
For /L %%a In (1,1,23) Do (
Set/A i+=1, percent=i*100/n, barLen=48*percent/100
For %%b In (!barLen!) Do Title !percent!%% !bar:~,%%b!
Echo( !i!- File%%a
Timeout 1 1>Nul)
Title Press any key to exit . . .
Timeout -1 1>Nul
Just run it then try to work it out.
This is probably impossible, but I have a loop that displays a animated logo by using TYPE to type logo_(framenumber).txt and the framenumber is determined by a loop:
:s
if %m%==379 set m=0
cls
TYPE Logo_%m%.txt
set /a m=%m%+1
goto s
I wanted to be able to use a set /p option and without disturbing/stopping the loop so the animation plays while a user is typing in the set /p input. I think there is a way to do it with FOR but I'm not sure how. Any ideas? Thanks.
Although this topic is somewhat old, I just discovered it. This is a pure Batch file solution that works pretty well:
EDIT: I slightly modified the code in order to made it simpler.
#echo off
setlocal EnableDelayedExpansion
if "%1" equ "Animate" goto %1
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
cd . > input.txt
start "" /B "%~F0" Animate
set "input="
:nextKey
set "key="
for /F "delims=" %%K in ('xcopy /W "%~F0" "%~F0" 2^>NUL') do if not defined key set "key=%%K"
if "!key:~-1!" equ "!CR!" goto endInput
if "!key:~-1!" equ "!BS!" (
if defined input set "input=%input:~0,-1%"
) else (
set "input=%input%!key:~-1!"
)
set /P "=%input%" > input.txt < NUL
goto nextKey
:endInput
del input.txt
echo/
echo/
echo Input read: "%input%"
goto :EOF
:Animate
set "banner= Enter your name please "
set m=0
:loop
if not exist input.txt exit
set /A m=(m+1)%%51
cls
echo/
echo/ !banner:~%m%,31!
echo/
echo/
if exist input.txt (type input.txt) else exit
ping -n 1 -w 300 localhost > NUL
ping -n 1 -w 300 localhost > NUL
ping -n 1 -w 300 localhost > NUL
goto loop
In this solution the animated "logo" is replaced by a banner, but the method to display a series of files is practically the same.
EDIT: This is possible in batch. See Aacini's answer.
This is not possible with batch files. Batch commands are single-threaded. To run two things simultaneously requires two instances of cmd.exe. But the console subsystem only allows one program to own the console at a time, so if the second instance of cmd is attached to the same console, one of them must be blocked.
It is possible to do something like this with a win32 executable which uses WriteConsoleOutput to modify the characters on the console screen. If you do that, you are no longer limited to just dumping text files, but the downside is that it's a lot more work than calling type in batch.
i want to make such as loading indicator just like : installation is running...
and those dots should be appear progressively and once they are three their number should be reinitialized to one dot and all happens in the same line.
for this i've tried to mix code of two small scripts : the first plays continuestly the dots
and the seconds makes a counter increase its value by echoing it in the same line.
at the end i got this code which is the closest solution for what i want to achieve but still with a problem which is that when there are already three dots, the next row which has less number of dots will overwrite its similar part from the previous one but the remaining part from the previous row will stay so at the end it looks like there are always three dots and all will looks like just a simple static echoed text..
here is the code :
#echo off
cls
setlocal EnableDelayedExpansion EnableExtensions
call :CreateCR
:spinner
set mSpinner=%mSpinner%.
if %mSpinner%'==.................................' (
set mSpinner=.
)
:: Wait one second.
ping 127.0.0.1 -n 2 >nul
set /P "=Installation Java en cours%mSpinner%!CR!" <nul
::set /p "=Installation Java en cours" <nul
::echo %mSpinner%
goto spinner
:exit
::echo(
goto :eof
:CreateCR
rem setlocal EnableDelayedExpansion EnableExtensions
set "X=."
for /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!
echo !X! > %temp%\cr.tmp
echo\>> %temp%\cr.tmp
for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do (
endlocal
set cr=%%a
goto :eof
)
goto :eof
You can capture a backspace character to a variable like this (courtesy of dbenham):
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
Then to erase your dots, simply send a number of
<NUL set /P "=%BS%"
... one %BS% for each dot you want to erase. As an alternative, you could use a spinner that spins instead of dots that grow. See this question and answer. In the answer there, insert the for /f line above to capture the backspace to %BS% at the top of the script, and replace all occurrences of ^H with %BS% in the spinner strings at the bottom.
A more simplistic approach would be the following:
#echo off
:spinner
set mSpinner=%mSpinner%.
if %mSpinner%'==....' (set mSpinner=.)
cls
echo Installation in progress%mSpinner%
ping 127.0.0.1 -n 2 >nul
goto spinner