echo won't display spaces...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
juicymixx
Posts: 1
Joined: 05 Jul 2015 18:16

echo won't display spaces...

#1 Post by juicymixx » 05 Jul 2015 18:25

Hey everyone, I'm playing around with updating a dos screen with a message; but doing so slowly. I hit upon tricking the set command and sending the result via pipe to echo... The problem with this is that spaces aren't being displayed. Is there a way around this? Standard escape character attempts fail here. Here's my code:

Code: Select all

@echo off

cls
set firsttext="This is a test: hello world!"
set /a nextchar=0

: firstloop
 set /a nextchar+=1
 CALL SET _substring=%%firsttext:~%nextchar%,1%%
 echo |set /p =^%_substring%
if %nextchar% LSS 28 goto firstloop

@echo ^>
ping localhost -n 3 > nul
echo %firsttext%

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: echo won't display spaces...

#2 Post by foxidrive » 05 Jul 2015 22:47

I wrote this once upon a time - is that the sort of thing you are trying to achieve?

Code: Select all

@:A Sunday school teacher was discussing the Ten Commandments with her
@:five and six year olds. After explaining the commandment
@:'Honour thy father and thy mother,' she asked
@:'Is there a commandment that teaches us how to treat our brothers
@:and sisters?'
@:
@:Without missing a beat one little boy answered, 'Thou shall not kill!'
@:
@:
@:
@:
@:
@:A father came in the bedroom to find his 14-year-old daughter
@:smoking a cigarette. 'My God! How long have you been smoking?'
@:screams the father.
@:
@:'Since I lost my virginity,' replies the girl.
@:
@:'You lost your VIRGINITY!!! When the hell did this happen?'
@:shrieks the father.
@:
@:'I don't remember,' says the girl. 'I was drunk.'




:: Add text above and start each line with @:
:: Do not use " in the text, replace them with '

@echo off
:: Ghost typer II

:: Adjust speed variable - higher numbers increase typing speed - default=3
set speed=3

for /f "tokens=1,* delims=:@" %%a in ('findstr /n "^@:" "%~f0" ') do (
    set "line-%%a=%%b"
    if "%%b"=="" set "line-%%a= "
    set "numlines=%%a"
)

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

for /L %%a in (1,1,%numlines%) do set num=0&call set "line=%%line-%%a%%"&call :type

pause>nul
goto :EOF

:type
call set "letter=%%line:~%num%,1%%"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul

for /L %%b in (1,%speed%,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto :type

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: echo won't display spaces...

#3 Post by Yury » 06 Jul 2015 04:05

juicymixx wrote:The problem with this is that spaces aren't being displayed.



You have problems not only with spaces, but also with quotes and with equal signs.

To avoid all these problems try this code:

Code: Select all

@echo off

set "firsttext="This is a test: hello world!""

for /f %%? in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x08"') do set BS=%%?
for /f "delims=" %%i in ('cmd/u/v/c echo.!firsttext!^| more^| findstr/n "^"') do set x=%%i& <nul (
 cmd/v/c "set x="!x:*:=!"& if !x! neq " " (if !x! neq "=" (set/p=!x!) else (set/p=.%BS%=)) else (set/p=.%BS% %)"
)

pause>nul& exit/b


.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: echo won't display spaces...

#4 Post by Ed Dyreen » 06 Jul 2015 09:48

juicymixx wrote:Hey everyone, I'm playing around with updating a dos screen with a message; but doing so slowly. I hit upon tricking the set command and sending the result via pipe to echo... The problem with this is that spaces aren't being displayed. Is there a way around this? Standard escape character attempts fail here. Here's my code:

Code: Select all

@echo off

cls
set firsttext="This is a test: hello world!"
set /a nextchar=0

: firstloop
 set /a nextchar+=1
 CALL SET _substring=%%firsttext:~%nextchar%,1%%
 echo |set /p =^%_substring%
if %nextchar% LSS 28 goto firstloop

@echo ^>
ping localhost -n 3 > nul
echo %firsttext%
You are not tricking the set command nor piping to echo, you are piping a linefeed into set, which makes set detect an EOL and it will close it's input you opened using the read input switch /P.

Code: Select all

@echo off

cls
setlocal disableDelayedExpansion
set firsttext="This is a test: hello world!"
setlocal enableDelayedExpansion
set /a nextchar=0

: firstloop
 set /a nextchar+=1
   set "_substring=!firsttext:~%nextchar%,1!"
   <nul set /p =!_substring!
if %nextchar% LSS 28 goto firstloop

@echo ^>
ping localhost -n 3 > nul
echo %firsttext%

echo(!firsttext!_
set firsttext
pause
exit

Code: Select all

This is a test: hello world!>
"This is a test: hello world"
"This is a test: hello world!"_
firsttext="This is a test: hello world!"
Druk op een toets om door te gaan. . .

Post Reply