The use of blank at the beginning, extension for set / p (without LineFeed)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

The use of blank at the beginning, extension for set / p (without LineFeed)

#1 Post by pieh-ejdsch » 25 Aug 2017 05:26

Hello,

I'm at the beginning flown over the blank - said Set /p. Now they come back.
Look at it and try it out.

Code: Select all

@echo off
:: This batch will allow the use of leading spaces as well as TAB at the beginning
::  of the line to start an endless line with these characters as well as to write
::  them again. Then set / p "= following text without new line" as usual used to
::  write the rest of the text into this line.
:: 
:: Please note the use of the characters from the command: "prompt /?"!
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal
if :%1 == :print shift &goto :print

 rem To execute an externally called command, which is enclosed in quotation marks
 rem  and quoted parameters (for / f ... in (cmd / c; cmd / k), the
 rem  first token is executed with a command that does not require quotation marks.

cmd /c if . equ . "%~f0" print "        please Input "
set /p"input=& pess Enter:
cmd /c if . equ . "%~f0" print "        "
echo %input%

set "output=%userprofile%\desktop\outputfile.txt"
set "LeadingSpace=cmd /c if . equ . "%~f0" print "

>"%output%" (
%LeadingSpace% "  "
<nul set /p"=endless Line begins with Space Space End with TAB TAB"
%LeadingSpace% "      "
)
notepad "%output%"
echo End
pause
exit /b

:print
 rem Please note that this function/batch can NOT be started with a call.
 rem  Since it terminates the calling batch.
 rem  Usage: cmd /c if. equ . "Path\batchname" "whiteSpaces ..."
@echo on
@(
setlocal
set "prompt=%~1"
)
%== !required this is an empty Line, do not remove! ==%
@( echo off


PS
uhhhmg ... You must fill in self the TAB into this script

Phil

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: The use of blank at the beginning, extension for set / p (without LineFeed)

#2 Post by Aacini » 25 Aug 2017 09:37

This is another method to get spaces at left of SET /P command:

Code: Select all

@echo off
setlocal

set /P "n=Enter number of spaces: "
call :CreateSpacesFile %n%
type spacesFile.txt
set /P "=After the spaces (press Enter)"
goto :EOF

:CreateSpacesFile
setlocal EnableDelayedExpansion
set "spcs="
for /L %%i in (1,1,%1) do set "spcs=!spcs! "
set /P ^"=X^
% Do not remove this line %
%spcs%^" > spacesFile1.tmp < nul
findstr /V "X" spacesFile1.tmp > spacesFile.txt
del spacesFile1.tmp
exit /B

I borrowed this method from jeb... :wink:

EDIT: Simpler method:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"

set /P "n=Enter number of spaces: "
set "spcs="
for /L %%i in (1,1,%n%) do set "spcs=!spcs! "
set /P "=X!BS!%spcs%After the spaces (press Enter)"

Antonio

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: The use of blank at the beginning, extension for set / p (without LineFeed)

#3 Post by thefeduke » 25 Aug 2017 23:55

A recent neighboring subject: "Colorful animation using VT100 - Pure batch WIN 10 only" shows a short method that handles leading and trailing spaces:

Code: Select all

@echo off & setlocal enableDelayedExpansion
 
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"

<nul set /p "=%ESC%[38;5;14m one leading and 2 trailing spaces  "%ESC%[0m
<nul set /p "=%ESC%[38;5;195m|"%ESC%[0m
echo.

pause & exit
Here's a little demo for the Win10 users:

Code: Select all

[@echo off & setlocal enableDelayedExpansion
 
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"

set "s=         "
 
for /l %%a in (0,1,9) do (

   set /a "r=9-%%a"

   <nul set /p "=%ESC%[38;5;11mprevious displayed field >|%ESC%[0m"
   If %%a GTR 0 (
     <nul set /p "=%ESC%[38;5;195m!s:~,%%a!%%a leading and !r! trailing spaces!s:~,-%%a!"%ESC%[0m
   ) Else <nul set /p "=%ESC%[38;5;195m!s:~,%%a!%%a leading and !r! trailing spaces!s!"%ESC%[0m
   <nul set /p "=%ESC%[38;5;1!r!8m|< next displayed field%ESC%[0m"
   echo.

)

pause & exit

John A.

Post Reply