Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Align text in batch file  (Read 19649 times)

0 Members and 1 Guest are viewing this topic.

graceguo

  • Guest
Align text in batch file
« on: January 11, 2006, 12:35:23 PM »
Hi,

I am writting a batch file to print the tests results. Like

if %errorlevel%==0 (
echo Test %test%  Passed >>output.txt
) else (
echo Test %test% Failed >>output.txt
)

Since the length of  %test% will change for different tests, Is there any way to let "Passed" or "Failed" start at the same column for all of the tests in output.txt.
Like

Test test1 flags         Passed
Test test2                Passed
...

Thanks for any help!

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Align text in batch file
« Reply #1 on: January 14, 2006, 06:51:28 AM »
Doubtful you can. You would need to insert a tab character (ascii 10) in each line. In an unformatted text file the tab character would be meaningless. Any of the scripting languages could do this.

Back to the drawing board. :)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

guest01



    Newbie

    • Experience: Beginner
    • OS: Windows XP
    Re: Align text in batch file
    « Reply #2 on: January 12, 2013, 08:47:27 PM »
    Not sure if this helps found this on the Hak5 forum maybe it helps

    Part 1   

    you need to amend it for your batch file

    cscript //nologo .\DUH.vbs >> ..\..\Documents\logfiles\%computername%.log 2>&1
    TYPE ..\..\Documents\logfiles\%computername%.log | find ":::" | find /V "NO PASSWORD" | find /V "ASPNET" | find /V "HelpAssistant" >> ..\..\Documents\logfiles\%computername%.log 

    Part 2

    .vbs file

    on error resume next
    set sh = createobject("Shell.Application")
    const ssfHISTORY = 34
    set history = sh.NameSpace(ssfHISTORY)
    for each item in history.items
       wscript.echo history.GetDetailsOf(item,-1)
       if item.isFolder then
          set itFol = item.GetFolder
          for each item2 in itFol.items
             wscript.echo vbtab & itFol.GetDetailsOf(item2,-1)
          Next
          wscript.echo String (80,"-")
       end if
    next


    Keep the vbs file in the same directory as the batch

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Align text in batch file
    « Reply #3 on: January 12, 2013, 09:38:46 PM »
    You dug up a 7 year old thread that I don't see how what you posted solved the OP's original question.

    Salmon Trout

    • Guest
    Re: Align text in batch file
    « Reply #4 on: January 13, 2013, 03:07:31 AM »
    You dug up a 7 year old thread that I don't see how what you posted solved the OP's original question.

    The question as stated was essentially unanswered, so see here, Google indexer!

    It is a simple matter to justify text in a batch script by padding it on the left or right with a suitable number of a pad character e.g. space, dot, whatever and then take a slice of desired length (as long as, or longer than the max length to be processed) starting at the left or right. These are just simple examples and of course refinements are possible.

    REM left justify text within a column 16 characters wide
    set string=some text
    REM add an excess of pad characters (i.e. more than 16)
    REM Note: use quotes if pad characters are spaces
    set "string=%string%                  "
    REM Show the justified column as a slice starting at position 0, of length 16
    echo Prefix %string:~0,16% Suffix

    REM right justify text within a column 16 characters wide
    set string=some text
    REM add an excess of pad characters on the left
    set string=                  %string%
    REM Show the justified column as a slice ending at the string end, of length 16
    echo Prefix %string:~-16% Suffix


    « Last Edit: January 13, 2013, 03:35:32 AM by Salmon Trout »