How To Start @echo off Script After @powershell Script in same BATCHFiLE?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DELvEK
Posts: 4
Joined: 12 Sep 2019 16:12

How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#1 Post by DELvEK » 12 Sep 2019 17:34

I was wondering if anyone knows if its possible to make a Batch script execute Powershell command and then execute @echo off right after?

Let me explain in more details.

I have a batch script
BATCH-COLORS.BAT
that open a CMD and animate my text and here is the code:

Code: Select all

@powershell "gc '%~f0'|select -skip 1|%%{$_.getenumerator()|%%{write-host $_ -nonewline -foregroundcolor black -backgroundcolor darkred;sleep -milliseconds 100};''}"& pause>nul& exit/b

[============================================]                                              
A SiMPLE BATCH COLORS TUTORiAL WiLL FOLLOW... 
                         PERSONAL REMENDER =D 
[============================================]
So that part is actually working but I would like to add a batch script into the same file.
BATCH-COLORS.BAT
• And execute it like-so when the animated text finish; I can press any key to continue (or ENTER) and it would clear the same cmd prompt and start the next batch script. Batch script I would like to start after animated text:

Code: Select all

@echo off
:TITLE
title DELvEK .BAT COLORS TUTORiAL
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
echo.
call :ColorText 02 "HERE iS SOME EXAMPLES OF BATCH COLORS"
echo.
echo ===========================================
call :ColorText 0a "light green"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0c "light red"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0b "light aqua"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0d "light purple"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0e "light yellow"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 07 "BLACK BACKGROUND on WHiTE TEXT"
echo.
call :ColorText 19 "BLUE BACKGROUND on LiGHTBLUE TEXT"
echo.
call :ColorText 2F "GREEN BACKGROUND on WHiTE TEXT"
echo.
call :ColorText 4e "RED BACKGROUND on LiGHTYELLOW TEXT"
echo.
echo ===========================================
call :ColorText 0a "MY LEGEND OF POSSiBLE COLORS iN NEXT PAGE"
echo.  
echo                                ~DELvEK
pause
goto CONFIRM
:CONFIRM
cls
call :ColorText 02 "WOULD YOU LiKE TO SEE THE LEGEND OF ALL POSSiBLE BATCH COLORS"
echo.
echo *MAXiMiZE YOUR CMD WiNDOW FOR BETTER RESULTS*
echo.
call :ColorText 0a "("
call :ColorText 09 " YES"
call :ColorText 0a " or"
call :ColorText 04 " NO"
call :ColorText 0a " )"
set/p "cho=>"
if %cho%==Y goto YES
if %cho%==YES goto YES
if %cho%==yes goto YES
if %cho%==y goto YES
if %cho%==n goto REFUSED
if %cho%==NO goto REFUSED
if %cho%==no goto REFUSED
if %cho%==N goto REFUSED
call :ColorText 04 "OOPS, iNVALiD CHOiCE"
pause
goto CONFIRM
:YES
cls
echo.
echo ===========================================
call :ColorText 0F "BATCH COLORS LEGEND _ BY DELvEK"
echo.
echo ===========================================
call :ColorText 0a "Colors are specified by"
call :ColorText 0F " TWO" 
call :ColorText 0a " hex digits"
echo.
call :ColorText 0a "The"
call :ColorText 0F " FiRST" 
call :ColorText 0a " correspond to the"
call :ColorText 0F " BACKGROUND"
echo.
call :ColorText 0a "The"
call :ColorText 0F " SECOND"
call :ColorText 0a " correspond the"
call :ColorText 0F " TEXT COLORS"
echo.
echo.
call :ColorText 0a "[eg]"
echo.
call :ColorText 0F "ColorText b0"
call :ColorText 0a " will give=" 
call :ColorText b0 "LiGHT AQUA BACK+BLACK FONT"
echo.
call :ColorText 0F "ColorText 2c"
call :ColorText 0a " will give=" 
call :ColorText 2c "GREEN BACK+LiGHT RED FONT"
echo.
call :ColorText 0F "ColorText 4b"
call :ColorText 0a " will give=" 
call :ColorText 43 "RED BACK+LiGHT AQUA FONT"
echo.
call :ColorText 0F "ColorText 1e"
call :ColorText 0a " will give=" 
call :ColorText 16 "BLUE BACK+LiGHT YELLOW FONT"
echo.
call :ColorText 0F "ColorText 6d"
call :ColorText 0a " will give=" 
call :ColorText 65 "YELLOW BACK+LiGHT PURPLE FONT"
echo.
call :ColorText 0F "ColorText 5f"
call :ColorText 0a " will give=" 
call :ColorText 5F "PURPLE BACK+LiGHT WHiTE FONT"
echo.
call :ColorText 0F "ColorText 70"
call :ColorText 0a " will give=" 
call :ColorText 70 "WHiTE BACK + BLACK FONT"
echo.
echo.
echo [Make your own with colors hex digits below]
echo ===========================================
echo 0 = Black    8  = Gray
echo 1 = Blue     9  = Light Blue
echo 2 = Green    A  = Light Green
echo 3 = Aqua     B  = Light Aqua
echo 4 = Red      C  = Light Red
echo 5 = Purple        D  = Light Purple
echo 6 = Yellow        E  = Light Yellow
echo 7 = White    F  = Bright White
echo ===========================================
call :ColorText 04 "                  DELvEK"
echo.
pause
cls
call :ColorText 04 "THE SCRiPT WiLL NOW RESTART..."
echo.
pause
cls
goto TITLE
:REFUSED
cls
call :ColorText 04 "OK BYE BYE, SEE YOU NEXT TiME  =D"
echo.
echo.
pause
goto END
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
:END
•And How to make when the second script restart it reload from the first script (animated text) instead of going back to TITLE..? •

I did not create theses script that I found on Google and they are both working good separately.
BUT I would like to join 2 of them in a single .BAT file.
I tried many many different methods and always not working or if it is working the first text is not animated anymore.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#2 Post by penpen » 13 Sep 2019 03:08

If you don't want to change the logic of the PS script, then you should just place it at the end of the combined batch file and just update to skip all lines up to the "@powershell" command.
That might help you:

Code: Select all

@call :psScript

:: place the content of the other batch file here

@goto :eof

:psScript
@setlocal enableExtensions
@for /f "delims=:" %%a in ('findstr /n "^@powershell" "%~f0"') do @(
	set "line=%%~a"
)
@powershell "gc '%~f0'|select -skip %line%|%%{$_.getenumerator()|%%{write-host $_ -nonewline -foregroundcolor black -backgroundcolor darkred;sleep -milliseconds 100};''}"& pause>nul& exit/b

[============================================]
A SiMPLE BATCH COLORS TUTORiAL WiLL FOLLOW... 
                         PERSONAL REMENDER =D 
[============================================]
penpen

Edit: Added some '@' characters to suppress unwanted output.

DELvEK
Posts: 4
Joined: 12 Sep 2019 16:12

Re: How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#3 Post by DELvEK » 13 Sep 2019 05:04

Thanks for your Fast repply.
Im getting this : (preview)
Image

when trying the code like this :

Code: Select all

@call :psScript
@echo off
:TITLE
title DELvEK .BAT COLORS TUTORiAL
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
cls
echo.
call :ColorText 02 "HERE iS SOME EXAMPLES OF BATCH COLORS"
echo.
echo ===========================================
call :ColorText 0a "light green"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0c "light red"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0b "light aqua"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0d "light purple"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0e "light yellow"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 07 "BLACK BACKGROUND on WHiTE TEXT"
echo.
call :ColorText 19 "BLUE BACKGROUND on LiGHTBLUE TEXT"
echo.
call :ColorText 2F "GREEN BACKGROUND on WHiTE TEXT"
echo.
call :ColorText 4e "RED BACKGROUND on LiGHTYELLOW TEXT"
echo.
echo ===========================================
call :ColorText 0a "MY LEGEND OF POSSiBLE COLORS iN NEXT PAGE"
echo.  
echo                                ~DELvEK
pause
goto CONFIRM
:CONFIRM
cls
call :ColorText 02 "WOULD YOU LiKE TO SEE THE LEGEND OF ALL POSSiBLE BATCH COLORS"
echo.
echo *MAXiMiZE YOUR CMD WiNDOW FOR BETTER RESULTS*
echo.
call :ColorText 0a "("
call :ColorText 09 " YES"
call :ColorText 0a " or"
call :ColorText 04 " NO"
call :ColorText 0a " )"
set/p "cho=>"
if %cho%==Y goto YES
if %cho%==YES goto YES
if %cho%==yes goto YES
if %cho%==y goto YES
if %cho%==n goto REFUSED
if %cho%==NO goto REFUSED
if %cho%==no goto REFUSED
if %cho%==N goto REFUSED
call :ColorText 04 "OOPS, iNVALiD CHOiCE"
pause
goto CONFIRM
:YES
cls
echo.
echo ===========================================
call :ColorText 0F "BATCH COLORS LEGEND _ BY DELvEK"
echo.
echo ===========================================
call :ColorText 0a "Colors are specified by"
call :ColorText 0F " TWO" 
call :ColorText 0a " hex digits"
echo.
call :ColorText 0a "The"
call :ColorText 0F " FiRST" 
call :ColorText 0a " correspond to the"
call :ColorText 0F " BACKGROUND"
echo.
call :ColorText 0a "The"
call :ColorText 0F " SECOND"
call :ColorText 0a " correspond the"
call :ColorText 0F " TEXT COLORS"
echo.
echo.
call :ColorText 0a "[eg]"
echo.
call :ColorText 0F "ColorText b0"
call :ColorText 0a " will give=" 
call :ColorText b0 "LiGHT AQUA BACK+BLACK FONT"
echo.
call :ColorText 0F "ColorText 2c"
call :ColorText 0a " will give=" 
call :ColorText 2c "GREEN BACK+LiGHT RED FONT"
echo.
call :ColorText 0F "ColorText 4b"
call :ColorText 0a " will give=" 
call :ColorText 43 "RED BACK+LiGHT AQUA FONT"
echo.
call :ColorText 0F "ColorText 1e"
call :ColorText 0a " will give=" 
call :ColorText 16 "BLUE BACK+LiGHT YELLOW FONT"
echo.
call :ColorText 0F "ColorText 6d"
call :ColorText 0a " will give=" 
call :ColorText 65 "YELLOW BACK+LiGHT PURPLE FONT"
echo.
call :ColorText 0F "ColorText 5f"
call :ColorText 0a " will give=" 
call :ColorText 5F "PURPLE BACK+LiGHT WHiTE FONT"
echo.
call :ColorText 0F "ColorText 70"
call :ColorText 0a " will give=" 
call :ColorText 70 "WHiTE BACK + BLACK FONT"
echo.
echo.
echo [Make your own with colors hex digits below]
echo ===========================================
echo 0 = Black 	  8  = Gray
echo 1 = Blue 	  9  = Light Blue
echo 2 = Green 	  A  = Light Green
echo 3 = Aqua 	  B  = Light Aqua
echo 4 = Red 	  C  = Light Red
echo 5 = Purple        D  = Light Purple
echo 6 = Yellow        E  = Light Yellow
echo 7 = White 	  F  = Bright White
echo ===========================================
call :ColorText 04 "               BY DELvEK"
echo.
pause
cls
call :ColorText 04 "THE SCRiPT WiLL NOW RESTART..."
echo.
pause
cls
goto TITLE
:REFUSED
cls
call :ColorText 04 "OK BYE BYE, SEE YOU NEXT TiME  =D"
echo.
echo.
pause
goto END
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
:END

@goto :eof

:psScript
setlocal enableExtensions
for /f "delims=:" %%a in ('findstr /n "^@powershell" "%~f0"') do (
	set "line=%%~a"
)

@powershell "gc '%~f0'|select -skip %line%|%%{$_.getenumerator()|%%{write-host $_ -nonewline -foregroundcolor black -backgroundcolor darkred;sleep -milliseconds 100};''}"& pause>nul& exit/b

[============================================]
A SiMPLE BATCH COLORS TUTORiAL WiLL FOLLOW... 
                         PERSONAL REMENDER =D 
[============================================]
•How can I make the script reload to the animated text when it restart instead of restarting at "TITLE" ?
- when I replace "goto TITLE" with "goto psScript" it works but the script close by itself when restarting ...
•Is it normal I see theses lines

Code: Select all

...for /F "delims=:" %a in ('findstr /n "^@powershell" "...\HELPED.bat"') do (set "line=%~a" )

...>(set "line=168" )
Thanks in advance
Attachments
preview.png
DELvEK
preview.png (74.64 KiB) Viewed 12703 times

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#4 Post by penpen » 13 Sep 2019 19:25

Sorry, i've forgotten to suppress some echoes.
I changed the above code a little bit (by adding some '@' characters).
Should work now.


penpen

DELvEK
Posts: 4
Joined: 12 Sep 2019 16:12

Re: How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#5 Post by DELvEK » 14 Sep 2019 00:08

its working as wanted thank you so much btw !
very fast answer and CLEAR! Love that :D
but the script close when it supposed to restart and it should work it does return to the animated text but as soon as I press a key it close..

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#6 Post by penpen » 15 Sep 2019 07:46

wrote:but the script close when it supposed to restart and it should work it does return to the animated text but as soon as I press a key it close..
I can't reproduce that behaviour (sorry - instead it loops all the time until typing "NO" in one of the screens), did you changed something else in your code?

The merged code i tested:

Code: Select all

@call :psScript
@echo off
:TITLE
title DELvEK .BAT COLORS TUTORiAL
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
echo.
call :ColorText 02 "HERE iS SOME EXAMPLES OF BATCH COLORS"
echo.
echo ===========================================
call :ColorText 0a "light green"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0c "light red"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0b "light aqua"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0d "light purple"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 0e "light yellow"
call :ColorText 02 " - "
call :ColorText 0F "   [black background]"
echo.
call :ColorText 07 "BLACK BACKGROUND on WHiTE TEXT"
echo.
call :ColorText 19 "BLUE BACKGROUND on LiGHTBLUE TEXT"
echo.
call :ColorText 2F "GREEN BACKGROUND on WHiTE TEXT"
echo.
call :ColorText 4e "RED BACKGROUND on LiGHTYELLOW TEXT"
echo.
echo ===========================================
call :ColorText 0a "MY LEGEND OF POSSiBLE COLORS iN NEXT PAGE"
echo.  
echo                                ~DELvEK
pause
goto CONFIRM
:CONFIRM
cls
call :ColorText 02 "WOULD YOU LiKE TO SEE THE LEGEND OF ALL POSSiBLE BATCH COLORS"
echo.
echo *MAXiMiZE YOUR CMD WiNDOW FOR BETTER RESULTS*
echo.
call :ColorText 0a "("
call :ColorText 09 " YES"
call :ColorText 0a " or"
call :ColorText 04 " NO"
call :ColorText 0a " )"
set/p "cho=>"
if %cho%==Y goto YES
if %cho%==YES goto YES
if %cho%==yes goto YES
if %cho%==y goto YES
if %cho%==n goto REFUSED
if %cho%==NO goto REFUSED
if %cho%==no goto REFUSED
if %cho%==N goto REFUSED
call :ColorText 04 "OOPS, iNVALiD CHOiCE"
pause
goto CONFIRM
:YES
cls
echo.
echo ===========================================
call :ColorText 0F "BATCH COLORS LEGEND _ BY DELvEK"
echo.
echo ===========================================
call :ColorText 0a "Colors are specified by"
call :ColorText 0F " TWO" 
call :ColorText 0a " hex digits"
echo.
call :ColorText 0a "The"
call :ColorText 0F " FiRST" 
call :ColorText 0a " correspond to the"
call :ColorText 0F " BACKGROUND"
echo.
call :ColorText 0a "The"
call :ColorText 0F " SECOND"
call :ColorText 0a " correspond the"
call :ColorText 0F " TEXT COLORS"
echo.
echo.
call :ColorText 0a "[eg]"
echo.
call :ColorText 0F "ColorText b0"
call :ColorText 0a " will give=" 
call :ColorText b0 "LiGHT AQUA BACK+BLACK FONT"
echo.
call :ColorText 0F "ColorText 2c"
call :ColorText 0a " will give=" 
call :ColorText 2c "GREEN BACK+LiGHT RED FONT"
echo.
call :ColorText 0F "ColorText 4b"
call :ColorText 0a " will give=" 
call :ColorText 43 "RED BACK+LiGHT AQUA FONT"
echo.
call :ColorText 0F "ColorText 1e"
call :ColorText 0a " will give=" 
call :ColorText 16 "BLUE BACK+LiGHT YELLOW FONT"
echo.
call :ColorText 0F "ColorText 6d"
call :ColorText 0a " will give=" 
call :ColorText 65 "YELLOW BACK+LiGHT PURPLE FONT"
echo.
call :ColorText 0F "ColorText 5f"
call :ColorText 0a " will give=" 
call :ColorText 5F "PURPLE BACK+LiGHT WHiTE FONT"
echo.
call :ColorText 0F "ColorText 70"
call :ColorText 0a " will give=" 
call :ColorText 70 "WHiTE BACK + BLACK FONT"
echo.
echo.
echo [Make your own with colors hex digits below]
echo ===========================================
echo 0 = Black    8  = Gray
echo 1 = Blue     9  = Light Blue
echo 2 = Green    A  = Light Green
echo 3 = Aqua     B  = Light Aqua
echo 4 = Red      C  = Light Red
echo 5 = Purple        D  = Light Purple
echo 6 = Yellow        E  = Light Yellow
echo 7 = White    F  = Bright White
echo ===========================================
call :ColorText 04 "                  DELvEK"
echo.
pause
cls
call :ColorText 04 "THE SCRiPT WiLL NOW RESTART..."
echo.
pause
cls
goto TITLE
:REFUSED
cls
call :ColorText 04 "OK BYE BYE, SEE YOU NEXT TiME  =D"
echo.
echo.
pause
goto END
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
:END

@goto :eof

:psScript
@setlocal enableExtensions
@for /f "delims=:" %%a in ('findstr /n "^@powershell" "%~f0"') do @(
	set "line=%%~a"
)
@powershell "gc '%~f0'|select -skip %line%|%%{$_.getenumerator()|%%{write-host $_ -nonewline -foregroundcolor black -backgroundcolor darkred;sleep -milliseconds 100};''}"& pause>nul& exit/b

[============================================]
A SiMPLE BATCH COLORS TUTORiAL WiLL FOLLOW... 
                         PERSONAL REMENDER =D 
[============================================]
penpen

DELvEK
Posts: 4
Joined: 12 Sep 2019 16:12

Re: How To Start @echo off Script After @powershell Script in same BATCHFiLE?

#7 Post by DELvEK » 16 Sep 2019 11:21

no. But its all fine and thank you again Im going to work with this and change the script to make it pause at the color legend and ask to quit or to reload the script into a new terminal instead and by default closing the first one.

thanks to you, very appreciated !

Post Reply