Colour code TEXT in a batch file!

Page 2 of 2 FirstFirst 12

  1. Posts : 38
    Windows 7 Lite: Professional 64-bit
       #11

    SIW2 said:
    As far as I know, what you are trying to do isn't natively supported.Unless you want to use some kind of software add on, you are wasting your time.
    You are correct; partially.

    Batch file scripting (cmd.exe is the process executed) does not allow for individually colored text/background.
    The command console (cmd.exe) is just another Windows program and does allow for the standardized native Win32 API calls to individually color (both intense and non-intense) of foreground and background characters.

    Strictly using the batch file language will only allow for coloring all of the characters at once (foreground or background).
    Without using external programs: I believe there is one method that allows you to link against the DLLs and call them; but the hack's not worth mentioning here.
      My Computer


  2. Posts : 16,132
    7 X64
       #12

    Then why mention it.
      My Computers


  3. Posts : 38
    Windows 7 Lite: Professional 64-bit
       #13

    Batch file scripting hackery (without the use of external programs other than the native Windows console and batch file scripting) does make it possible.

    A simple correction for anyone who may decide to investigate further.
      My Computer


  4. Posts : 16,132
    7 X64
       #14

    If you have come across an obscure workaround, then instead of being obtuse, you could link to it.
      My Computers


  5. Posts : 38
    Windows 7 Lite: Professional 64-bit
       #15

    I wasn't trying to be obtuse.

    Firstly: I was unaware of whether or not outside links were against the rules.
    Secondly: The forum they're on is not open (linking would be senseless).

    If the latter were not true: I'd be happy to oblige and post it for the OP.
      My Computer


  6. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #16

    Paul Black said:
    Good afternoon,

    I have written a batch file which works great!
    However, I would like to colour several pieces of text within the batch file.
    I have spent a LONG time researching this on Google and I am almost there.

    This is what I have at the top of the code...

    Code:
    @echo off
     
    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"
    )
    This is what I have as an example that I want to colour red [which it does]...

    Code:
    call :ColorText 0c "     IMPORTANT - Numbers 2 blah blah."
    call :ColorText 0c "                    If you blah blah!" & set /p ".= " < nul
    echo.
    This is what I have as the :ColorText code...

    Code:
    :ColorText
    rem echo off
    <nul set /p ".=%DEL%" > "%~2"
    findstr /v /a:%1 /R "^$" "%~2" nul
    del "%~2" > nul 2>&1
    GOTO :EOF
    The questions I have are...

    [1] If I put a colon [:] after Important, is doesn't work, hence the dash [-]?
    [2] Why will it not show the exclamation [!] at the end of the line although it is there?
    [3] Why will it not show the full stop [.] at the end of the line although it is there?
    [4] Is there a way to split the call :ColorText 0c " IMPORTANT - Numbers 2 blah blah." over two lines so it makes it esaier to read and also lines up in the script with the code below it. I tried several options, all to no avail!
    [5] As you see from the middle piece of code, the Numbers 2 and If you are not lined up, but they are in the consol!
    [6] Why doesn't it put a blank row after even though there is a echo. after the text to be coloured, but it does if I use & set /p ".= " < nul end & echo..
    [7] It will also not accept forward slash [/]!

    Thanks in advance.
    How to have multiple colors in a Windows batch file | Code Q&A Solved

    What are the undocumented features and limitations of the Windows findstr command
      My Computer


 
Page 2 of 2 FirstFirst 12

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:57.
Find Us