How should I print this in a .bat file? [duplicate] - batch-file

This question already has answers here:
How do escape echo " for storing in a file?
(2 answers)
Closed 6 years ago.
echo ping localhost -n 4 > nul >>TEST.bat
When I print this in a .bat file, for example, the "> nul" disappears. How can i just print "> nul" as a string way?

To esacpe > or < or | just add the carret ^
#echo off
Color 0E
(
echo cls
echo #echo off
echo Color 0B
echo echo Please Wait a while ....
echo ping localhost -n 4 ^> nul
)>TEST.bat
cls
echo.
echo Type any key to read the contents of your new batch file
pause>nul
echo.
Type TEST.bat
pause>nul
cls
echo.
echo Type any key to execute your new batch file ...
pause>nul
TEST.bat

Related

Is there a way to write a variables name in a bat file using bat?

I'm asking this because I want to make a download file for a simple website IP finder I made. Here is the code so far:
#echo off
color 03
SET /P user=Enter the user you are using here:
echo.>>"C:\Users\%user%\desktop\WebIPFind.bat"
echo #echo off > WebIPFind.bat
echo color 03 >> WebIPFind.bat
echo :loop >> WebIPFind.bat
echo SET /A ip=%ip%+1 >> WebIPFind.bat
echo ECHO IP No. %ip% >> WebIPFind.bat
echo SET /P website=Enter a website URL: >> WebIPFind.bat
echo ping %website% -l 8 -w 1 -n 1 >> WebIPFind.bat
echo goto :loop >> WebIPFind.bat
but when I use this it just replaces the variables with blank spaces. Is there a way to make it so it writes the names of the variables? (I don't need the user variable to be written because that is used to select where to write the bat file)
Your modified sample, like T3RROR explained
#echo off
color 03
SET /P user=Enter the user you are using here:
(
echo(
echo #echo off
echo color 03
echo :loop
echo SET /A ip=ip+1
echo ECHO IP No. %%ip%%
echo SET /P website=Enter a website URL:
echo ping %%website%% -l 8 -w 1 -n 1
echo goto :loop
) >>"C:\Users\%user%\desktop\WebIPFind.bat"

Youtube-dl cannot read various set on batch script

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 .

How to echo line break in batch while merging files in all subdirectories? [duplicate]

This question already has answers here:
Echo a blank (empty) line to the console from a Windows batch file [duplicate]
(3 answers)
Closed 5 years ago.
I need to merge all files in a directory and its subdirectories into one. Based in solutions, I've this code below (I'd like to improve...):
Set output="evoc.lua"
Del %output%
(
Type hoist.lua
Echo.
Echo.
For /r "./src/" %%a in (*.lua) do #(
type "%%a"
)
Echo.
Echo.
Type "exec.lua"
) >> %output%
It works. Now I need to distinguish files by line breaks (e.g., '\r\n' or \n); I've tried with Echo., but it puts dots (not at all). Any solutionsw
Set output="evoc.lua"
Del %output%
(
Type hoist.lua
Echo.
Echo.
For /r "./src/" %%a in (*.lua) do #(
type "%%a"
Echo.
)
Echo.
Echo.
Type "exec.lua"
) >> %output%
The problem with echo. is an old friend of batch files. It seems that there is no perfect solution to print new lines that work in all the cases.
These are some alternatives that you can try:
Echo/
Echo\
Echo:

FTP download progress bar in batch file

I wonder if there is a possibility the code below to enable a progress bar or percentage counter to check the progress of download, however alternativar not seen since the download is being executed by the FTP client.
Follows the code:
ECHO OFF
Color 17
Setlocal ENABLEDELAYEDEXPANSION
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO . Selecione o numero desejado no menu abaixo .
ECHO ...............................................
ECHO.
ECHO 1 - Atualizar Frente/Retaguarda
ECHO 2 - Atualizar Rgourmet
ECHO 3 - Exit
ECHO.
SET /P M=Selecione 1, 2, ou 3 e pressione ENTER:
IF %M%==1 GOTO FRENTE
IF %M%==2 GOTO RGOURMET
IF %M%==3 GOTO SAIR
:FRENTE
# echo off
echo open 177.125.217.138>>frente.ftp
echo ****>>frente.ftp
echo ****>>frente.ftp
echo hash>>frente.ftp
echo cd atualizador>>frente.ftp
echo binary>>frente.ftp
echo get "libx12.dll">>frente.ftp
echo get "rjkmonitor.exe">>frente.ftp
echo get "rjkini.exe">>frente.ftp
echo quit>>frente.ftp
# echo off
echo off taskkill /F /IM rjkpdv.exe > NUL
echo off taskkill /F /IM libx12.dll > NUL
echo off taskkill /F /IM rjkretaguarda.exe > NUL
ftp -v -i -s:frente.ftp
if exist macro.txt (
rjkpdv.exe /a
rjkini.exe
) else (
del rjkretaguarda.exe
ren libx12.dll rjkretaguarda.exe
rjkretaguarda.exe /a
rjkini.exe
)
del frente.ftp
cls
GOTO MENU
:RGOURMET
# echo off
taskkill /F /IM rgourmet.exe
taskkill /F /IM rmt.exe
echo open 177.125.217.138>>rgourmet.ftp
echo ****>>rgourmet.ftp
echo ****>>rgourmet.ftp
echo hash>>rgourmet.ftp
echo cd atualizador>>rgourmet.ftp
echo binary>>rgourmet.ftp
echo get "rgourmet.exe">>rgourmet.ftp
echo get "rmt.exe">>rgourmet.ftp
echo get "rjkini.exe">>rgourmet.ftp
echo quit>>rgourmet.ftp
# echo off
ftp -v -i -s:rgourmet.ftp
rgourmet.exe /asgb
rjkini.exe
del rgourmet.ftp
cls
GOTO MENU
:SAIR
exit
The build-in Windows command-line FTP client (ftp.exe) cannot display progress of the transfer. All it can do, is what you already get with the hash command.
You have to use another FTP client to get percentage progress.
For example with WinSCP FTP client, you get the percentage progress by default.
winscp.com /command ^
"open ftp://rjk:password#177.125.217.138/" ^
"cd atualizador" ^
"get libx12.dll" ^
"get rjkmonitor.exe" ^
"get rjkini.exe" ^
"exit"
See a guide for converting Windows FTP script to WinSCP script.
(I'm the author of WinSCP)

how do you echo text from a file using batch?

okay, so I'm trying to make a batch file that just echos the text inside a file called "test.txt" and my code is
#echo off
cls
(
echo %0%
echo %1%
echo %2%
echo %3%
echo %4%
echo %5%
echo %6%
echo %7%
echo %8%
echo %9%
echo %10%
echo %11%
echo %12%
echo %13%
echo %14%
echo %15%
echo %16%
) <test.txt
pause >nul
but for some very strange reason I couldn't find any answers for anywhere, my output is
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
0
1
2
3
4
5
6
and I really don't understand why.
If you want to echo the text that's inside your test.txt file, then you need to add this line to your batch file as already said by #Blorgbeard.
type C:\..\test.txt
#pause
Adding this line to your batch file will display the text/contents of a file in the command prompt window.
Copy the numbers below into test.txt on your desktop.
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.
Now copy and paste the code below into print.bat on your desktop.
#ECHO OFF
type "%UserProfile%\Desktop\test.txt"
#pause
now run print.bat
REM:: Big thanks to Rakitić, Blorgbeard & Hackoo.
With this batch file you can echo your test.txt file :
#echo off
Set "MyFile=test.txt"
for /f "delims=" %%a in ('Type "%MyFile%"') Do (
echo %%a )
pause

Resources