I'm trying to simulate a progress bar with ASCII characters, but any time my progress bar is more than 0% full, the message echo is OFF is displayed.
#echo off
setlocal EnableDelayedExpansion
color A
echo hacking main intelligence systems...
ping -n 2 127.0.0.1>nul
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Loading... Please Wait
echo ---------------------------------------
echo :0 ]
echo ---------------------------------------
ping localhost -n 2 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Loading. Please Wait
echo ---------------------------------------
echo || :5 ]
echo ---------------------------------------
ping localhost -n 3 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Loading.. Please Wait
echo ---------------------------------------
echo |||| :15 ]
echo ---------------------------------------
ping localhost -n 2 >nul
The script continues on like that for a while, but this snippet is smaller and has the same issue.
What is causing the message to appear, and how can I correctly display the bar progressing?
Your actual question of why your echos aren't working is perfectly reasonable, and it's an extremely common error for beginners.
| is a symbol that takes the output of one command and uses it as the input of another command. In your case, you effectively have echo by itself, which will simply return the status of echo (in this case, echo is OFF).
In order to get around this, you can either use a different symbol, or you can open your code in a text editor and replace all instances of | with ^|.
^ is an escape character, which tells echo to interpret the symbol literally and print an actual | instead of using it to route command output.
#echo off
setlocal EnableDelayedExpansion
color A
echo hacking main intelligence systems...
ping -n 2 127.0.0.1>nul
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Loading... Please Wait
echo ---------------------------------------
echo :0 ]
echo ---------------------------------------
ping localhost -n 2 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Loading. Please Wait
echo ---------------------------------------
echo ^|^| :5 ]
echo ---------------------------------------
ping localhost -n 3 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Loading.. Please Wait
echo ---------------------------------------
echo ^|^|^|^| :15 ]
echo ---------------------------------------
ping localhost -n 2 >nul
Related
I created an batch-script that positioned with youtube-dl and ffmpeg. I set several set to put URL and Video/Audio ID. Here my script that I simplified
#echo off
cd /d %root%\YT
color 0a
title Youtube Downloader
setlocal enableDelayedExpansion
set q=^"
color 0a
:submenu
echo Please enter URL.
set /p f1="URL: "
echo Checking ID...
youtube-dl -F %f1%
ping localhost -n 2 >nul
goto menu
:menu
echo.
echo Script created by UrbaseR
echo ___________________________________________________________
echo.
echo MENU
echo ___________________________________________________________
echo OS Windows - %ComputerName%
echo.
echo M E N U
echo Press 1 to Download Best version
echo Press 2 to Download Custom version + convert
echo Press 3 to Exit
set /p you=">"
if %you%==1 goto 1
if %you%==2 goto 2
if %you%==3 goto 3
cls
echo *********************************
echo Sorry invalid number!
echo *********************************
ping localhost -n 2 >nul
goto menu
:1
echo Downloading...
youtube-dl -f best %f1%
echo.
echo Done
ping localhost -n 2 >nul
cls
goto submenu
:2
set /p id1="Insert Video ID: "
set /p id2="Insert Audio ID: "
echo Downloading Video..
youtube-dl -f %id1% -ciw -o "vid.%(ext)s" -v --write-sub %f1%
echo.
echo Video Done
ping localhost -n 2 >nul
echo Downloading Audio..
youtube-dl -f %id2% -ciw -o "aud.%(ext)s" -v %f1%
echo.
echo Audio Done
ping localhost -n 2 >nul
echo Converting Video
ffmpeg -i "vid.%(ext)s" -i "aud.%(ext)s" -c:v copy -c:a aac -strict experimental "input.mkv"
echo Converting Done
ping localhost -n 4 >nul
cls
goto submenu
:3
exit
First and third option execute successfully. Second option will appear the message like this:
Usage: youtube-dl [OPTIONS] URL [URL...]
youtube-dl: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.
Note: Since I stuck on first and second stage of youtube-dl, ffmpeg may not work (I have not tested it yet).
Can you help me?
After re-fix the script is pretty much done.
#echo off
cd /d %root%\YT
color 0a
title Youtube Downloader
setlocal enableDelayedExpansion
set q=^"
color 0a
:submenu
echo Please enter URL.
set /p f1="URL: "
cls
echo Checking ID...
youtube-dl -F %f1%
ping localhost -n 2 >nul
goto menu
:menu
echo.
echo.
echo Script created by UrbaseR
echo ___________________________________________________________
echo.
echo MENU
echo ___________________________________________________________
echo OS Windows - %ComputerName%
echo.
echo M E N U
echo Press 1 to Download Best version (default ver)
echo Press 2 to Download Custom version + Convert
echo Press 3 to Exit
echo.
echo URL: %f1%
set /p you=">"
if %you%==1 goto 1
if %you%==2 goto 2
if %you%==3 goto 3
cls
echo *********************************
echo Sorry invalid number!
echo *********************************
ping localhost -n 2 >nul
goto menu
:1
echo Downloading...
youtube-dl -f best %f1%
echo.
echo Done
ping localhost -n 2 >nul
cls
goto submenu
:2
set /p id1="Insert Video ID: "
set /p id2="Insert Audio ID: "
set ida="v.data"
set idb="a.data"
set "f2="
set "f3="
cls
echo Downloading Video..
youtube-dl -f %id1% -ciw --o %ida% -v --write-sub %f1%
echo.
echo Video Done
ping localhost -n 2 >nul
cls
echo Downloading Audio..
youtube-dl -f %id2% -ciw -o %idb% -v %f1%
echo.
echo Audio Done
ping localhost -n 2 >nul
cls
echo Note Default title is: input.mkv
echo.
set /p f2="Enter Video Title: "
if not defined f2 set "f2=input"
set /p f3="Format Video: "
if not defined f3 set "f3=mkv"
echo Converting Video..
ffmpeg -i %ida% -i %idb% -c:v copy -c:a aac -strict experimental "%f2%.%f3%"
echo Converting Done
del /q %ida%
del /q %idb%
ping localhost -n 4 >nul
cls
goto submenu
:3
exit
Feel free to use the script.
Note: Be sure to have youtube-dl.exe and ffmpeg.exe on same folder, video will also saved on same folder .
Batch language.
So, I made a small text editor called microPad. It can create a file, but I don't know how to have it open a file and write to it. Any ideas?
(I want to add another marker block called 'oeditor' at the end, after 'neditor'
#echo off
color c
title microPad v1.02
:options
echo ----------------------------------
echo microPad v1.02
echo ----------------------------------
echo.
echo 1 - Create a new document.
echo 2 - Preferences.
set /p opt=Select an option number.
if %opt%==1 goto neditor
if %opt%==2 goto prefs
if NOT %opt%==2 goto notopt
:notopt
cls
echo That isn't an option.
timeout -t 1 >nul
cls
goto options
:prefs
cls
echo 1 - Change the color.
echo 2 - Change the window size.
echo 3 - Return to options screen.
set /p prefopt=^>^>
if %prefopt%==1 goto colorpref
if %prefopt%==2 goto sizepref
if %prefopt%==3 goto options
if NOT %prefopt%==3 goto notopt
:colorpref
cls
set /p colors=^>^>
color %colors%
goto prefs
:sizepref
cls
echo The size should be between 50 and 1000.
set /p size=^>^>
mode %size%
:titling
echo ----------------------------------
echo microPad v1.02
echo ----------------------------------
echo.
echo.
echo Input the filename and remember to use the file extension.
set /p fname=">> "
timeout -t 1 >nul
title %fname% - microPad v1.02
cls
echo ----------------------------------
echo microPad v1.02
echo ----------------------------------
echo.
:neditor
set /p content=">> "
echo %content%>>%fname%
goto neditor
I am trying to write a batch script that simulates a progress bar, using | characters to show progression.
Unfortunately, whenever I try to show the progress bar, I get the error "The syntax of the command is incorrect." What am I doing wrong?
My code:
#echo off
color 0F
mode con: cols=51 lines=18
cls
echo _____________
echo. |
echo _____________
You're using the pipe character (|), but that won't work. You have to escape it with ^.
#echo
color 0F
mode con: cols=51 lines=18
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|
echo _____________
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 1 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 2 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo COMPLETE
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 2 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
ping localhost -n 2 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo
ping localhost -n 2 >nul
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo COMPLETE
echo =============
echo.
echo _____________
echo. ^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
echo =============
cls
There are techniques to avoid repainting a screen over and over.
The set /P (input) command allows echoing without a crlf.
Any letter key will abort the loop.
#echo off
color 0F
mode con: cols=51 lines=18
cls
echo.
echo.
echo.
echo.
echo.
echo =============
echo Initializing.
echo =============
echo.
echo _____________
Set /p _=". "0<NUL
For /L %%A in (1,1,20) Do (
Set /P dummy=^|<NUL
CHOICE /T 1 /C 1ABCDEFGHIJKLMNOPQRSTUVWXYZ /D 1 >NUL
if errorlevel 2 goto :Eof
)
How to make this BATch file have a timer?
Would like to see how much time left. Windows only says "Windows will shut down in less then a minute".
#echo off
color 0A
title Restart\/Shutdown
:start
echo Welcome, %USERNAME%
echo What would you like to do?
echo.
echo 1. Shut down
echo 2. Restart
echo.
echo 0. Quit
echo.
set /p choice="Enter your choice: "
if "%choice%"=="1" goto shutdown
if "%choice%"=="2" goto restart
if "%choice%"=="0" exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start
:shutdown
shutdown.exe -s -t 10
:restart
shutdown.exe -r -t 10
You could use the command "timeout /t 10" or something like:
#ECHO OFF
FOR /L %%# IN (10,-1,1) DO (SET/P "=%%# seconds left... "<NUL:
PING -n 2 127.0.0.1 >NUL
CLS:)
#ECHO off
cls
color 0B
:taskkill
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Program To Shutdown
echo.
set /p taskkill=
if "%taskkill%" == "%taskkill%" goto taskkillconfirm
exit
:taskkillconfirm
color 0B
:image
set image=/im
if "%image%" == "%image%" goto imageconfirm
exit
:imageconfirm
color 0B
:forced
set forced=/f
if "%forced%" == "%forced%" goto forcedconfirm
exit
:forcedconfirm
:hour
color 0B
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo. Hours?:
echo.
set /p hour=
:min
color 0B
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Minutes?:
echo.
set /p min=
:sec
color 0B
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Seconds?:
echo.
set /p sec=
:continue
color 0B
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo %taskkill% Shutdown in
echo.
echo %hour% Hours %min% Minutes %sec% Seconds
set /a sec="%sec%-1"
if %sec%==-1 set /a min="%min%-1"
if %sec%==-1 set /a sec="59"
if %min%==-1 set /a hour="%hour%-1"
if %min%==-1 set /a min="59"
if %hour%==-1 goto done
ping -n 2 127.0.0.1 >NUL
goto continue
:done
color 0B
cls
taskkill %image% %taskkill% %forced%
exit
" ping localhost -n 10 >nul " take off quotations and to edit the amount of seconds replace the 10 with whatever you
when i run it does not pause after the fist frame please help
#echo off
title line!
color 0a
echo.
echo -----------------------------------
echo press a key to Make The line spin
echo -----------------------------------
echo.
echo Made By: alex.page
echo.
pause >nul
echo -----------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo \
echo \
echo \
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo |
echo |
echo |
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo /
echo /
echo /
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo \
echo \
echo \
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo |
echo |
echo |
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo /
echo /
echo /
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo \
echo \
echo \
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo |
echo |
echo |
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo /
echo /
echo /
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo \
echo \
echo \
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo |
echo |
echo |
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo /
echo /
echo /
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo ------------------
echo.
echo.
echo.
echo \
echo \
echo \
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo |
echo |
echo |
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo /
echo /
echo /
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo \
echo \
echo \
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo |
echo |
echo |
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo /
echo /
echo /
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
echo -----------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
pause
The | character is special to the command interpreter and must be escaped with a ^. You want to use this instead:
echo ^|
Here is what I was talking about regarding the animation labels. For simplicity I used two frames, but the proof of concept is what's important.
#echo off
title Spin
color 0a
echo.
echo -----------------------------------
echo Press a key to make the line spin!
echo -----------------------------------
echo.
echo.
pause >nul
cls
:Animate
Call :Frame1
Call :Frame2
Call :Frame1
Call :Frame2
echo Spin complete!
pause>nul
exit
:Frame1
echo -----------------
echo.
echo.
echo.
echo.
echo ---
echo.
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
GOTO:EOF
:Frame2
echo -----------------
echo.
echo.
echo.
echo ^|
echo ^|
echo ^|
echo.
echo.
echo.
echo.
echo ------------------
ping localhost -n 1 >nul
cls
GOTO:EOF