Batch Menu Output issues

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
B33LLZ
Posts: 2
Joined: 05 Jan 2014 02:26

Batch Menu Output issues

#1 Post by B33LLZ » 05 Jan 2014 03:21

Hello,

I'm having some difficulty getting a batch menu to display correctly:

Code: Select all

   echo.- Results 1 = %A% of %B%:
   echo.
   TYPE File1.out
   echo.
   echo.- Results 2 = %C% of %D%:
   echo.
   TYPE File2.out
   echo.
   echo.- Results 3 = %E% of %F%
   echo.
   TYPE File3.out
   echo.
   echo.- Results 4 = %G% of %H%
   echo.
   TYPE File4.out


CMD output:

Code: Select all

- Results 1 = 1 of 4:

ABC123

- Results 2 = 0    of 3:

DEF456

- Results 3 = 1 of 4

GHI789

- Results 4 = 3 of 4

KLM012


1. Is it possible to make TYPE output further to the right of the screen? It seems the only option is for the File output to "hug" the left of the screen - is there a better way of achieving this result?

2. "- Results 2 = 0 of 3:" - Why is %C% adding three spaces after the output of 0? Although a little confusing, here's how %C% gets its value via file input:

Code: Select all

   IF EXIST Ref1.old DEL /F /Q Ref1.old
   IF EXIST Ref1.out RENAME Ref1.out Ref1.old
   
   FOR /f %%X in (Ref2.out) DO @( IF EXIST echo.%%X>>Ref1.out )
   
   FINDSTR /V /G:Ref2.out Ref1.out>File2.out


Code: Select all

   RENAME File2.out File2.wip
      TYPE File2.wip | findstr /I /V /C:"NULL" > File2.out
         DEL /F /Q File2.wip


Code: Select all

   SET C2=0
:R3

   FOR /f %%i in ("File2.out") do set size=%%~zi
      IF %FILE% equ 0 GOTO R4

   FOR /f %%B in ('Find /V /C "" ^<File2.out') do set C2=%%B   
   
   GOTO R5
   
:R4
   SET C2=0
:R5


Reason I took the above approach was to ensure if no input value provided, manually input 0. Same approach taken with the other variables and no problems. I've taken my time to carefully check for spaces, tabs, soft-returns etc - basically anything before or after the '0' yet no luck and it's the only variable doing it.

Thanks for taking the time to check this out, really would appreciate any help or advice provided.

B33lzz

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

Re: Batch Menu Output issues

#2 Post by foxidrive » 05 Jan 2014 03:41

This line has trailing spaces. You can use this syntax with variables to eliminate the possibility of unwanted spaces: set "C2=%%B"

Code: Select all

FOR /f %%B in ('Find /V /C "" ^<File2.out') do set C2=%%B   


The type command always outputs text on the left margin, but you can add leading spaces in the file, or use a technique to add them like this, where there are spaces after the echo command.


Code: Select all

for /f "usebackq delims=" %%a in ("fileB.txt") do echo.                  %%a

B33LLZ
Posts: 2
Joined: 05 Jan 2014 02:26

Re: Batch Menu Output issues

#3 Post by B33LLZ » 05 Jan 2014 06:57

Thanks foxidrive - great advice that solved both issues.

Minor adjustment on the second suggestion though:

Code: Select all

for /f "usebackq delims=" %%a in ("fileB.txt") @do echo.                  %%a


Had to make both of the variables the same letter and add a @ before it did want I was after but thank you very much for your help!!!

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

Re: Batch Menu Output issues

#4 Post by foxidrive » 05 Jan 2014 07:00

Yes, I typo'd that %%b.

The @ sign isn't needed though.

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

Re: Batch Menu Output issues

#5 Post by penpen » 05 Jan 2014 09:40

If the typed output is less than one line and short enough to allow spaces without wrap at the cmd-shell window, then you may adjust it using set:

Code: Select all

(set/P"=          " <nul)&type File.txt

penpen

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch Menu Output issues

#6 Post by aGerman » 05 Jan 2014 14:49

@penpen
This may work under XP. On newer Windows versions SET /P removes leading white spaces.

Regards
aGerman

Post Reply