You are not logged in.

#1 03 Dec 2015 19:34

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Whats wrong with this code

I found the following code but i'm not sure why it doesn't work it gives me this out put

Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\User>ncol hello 04
'"hello.@"' is not recognized as an internal or external command,
operable program or batch file.
FINDSTR: Cannot open *.@

here's the code

@echo off
setlocal
if "%~1"=="/?" (
echo.
echo    ncol ["Text"] [Colour]
echo.
echo "Text" - The text you want displayed in another colour.
echo          Remember that spaces cannot be added if you don't put the text in
echo          quotation marks (""^).
echo.
echo Colour - The hexadecimal colour code that you want the text to be changed into.
echo          For more information of colour codes, see "color /?"
echo.
exit /b
)
for /f "delims=#" %%i in ('"prompt #$H# &for %%b in (1) do rem"') do set "bs=%%i"
"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"
findstr /p /a:%2 . "*.@"
endlocal
del "*.@"
@echo on
@exit /b

Here is the final code

@echo off
setlocal
if "%~1"=="/?" (
echo.
echo    ncol ["Text"] [Colour]
echo.
echo "Text" - The text you want displayed in another colour.
echo          Remember that spaces cannot be added if you don't put the text in
echo          quotation marks (""^).
echo.
echo Colour - The hexadecimal colour code that you want the text to be changed into.
echo          For more information of colour codes, see "color /?"
echo.
exit /b
)
for /f "delims=#" %%i in ('"prompt #$H# &for %%b in (1) do rem"') do set "bs=%%i"
>"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"<nul
findstr /p /a:%2 . "*.@"
endlocal
del "*.@"
@echo on
@exit /b

Last edited by Batcher (04 Dec 2015 17:56)

Offline

#2 04 Dec 2015 11:14

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Whats wrong with this code

This line is where the error is coming from:

"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"

Your intent on that line is unclear.

The problem of misusing "findstr" to produce arbitrary coloured output has been solved quite exhaustively elsewhere:

http://www.dostips.com/forum/viewtopic.php?f=3&t=4881


cmd | *sh | ruby | chef

Offline

#3 04 Dec 2015 11:51

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Whats wrong with this code

It should be

>"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"<nul

Offline

Board footer

Powered by