| 1. |
Solve : output on second batch? |
|
Answer» hi all type chat.txt display.bat Code: [Select]@echo off mode 20, 32 setlocal disableDelayedExpansion set user=user :loop echo --- type chat.txt echo --- cls goto loop input.bat Code: [Select]@echo off mode 20, 4 title taip in color 02 if exist chat.txt del chat.txt if not exist chat.txt echo Welcome to chat system >>chat.txt :loop set /p message= echo %user%: %message%>>chat.txt goto loop now how can i make content in chat.txt like this Quote user=kaka and on display.bat show like this Quote kaka: message1because its easy i want to make kaka different color Quote kaka: message1 this code i able made so far display.bat Code: [Select]@echo off mode 20, 32 title start6 start input.bat setlocal disableDelayedExpansion set user=kaka set q=^" echo( call :c 02 "%messageV%" /n call :c 04 "%messagex%" /n call :c 02 "%downloadV%" /n call :c 04 "%downloadx%" /n call :c 02 "%doneV%" /n call :c 04 "%donex%" /n :loop echo --- type chat.txt echo --- ping -n 3 localhost >nul cls goto loop :c setlocal enableDelayedExpansion ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :colorPrint Color Str [/n] setlocal set "s=%~2" call :colorPrintVar %1 s %3 exit /b :colorPrintVar Color StrVar [/n] if not defined DEL call :initColorPrint setlocal enableDelayedExpansion pushd . ': cd \ set "s=!%~2!" :: The single blank line within the following IN() clause is critical - DO NOT REMOVE for %%n in (^"^ ^") do ( set "s=!s:\=%%~n\%%~n!" set "s=!s:/=%%~n/%%~n!" set "s=!s::=%%~n:%%~n!" ) for /f delims^=^ eol^= %%s in ("!s!") do ( if "!" equ "" setlocal disableDelayedExpansion if %%s==\ ( findstr /a:%~1 "." "\'" nul <nul set /p "=%DEL%%DEL%%DEL%" ) else if %%s==/ ( findstr /a:%~1 "." "/.\'" nul <nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%" ) else ( >colorPrint.txt (echo %%s\..\') findstr /a:%~1 /f:colorPrint.txt "." <nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" ) ) if /i "%~3"=="/n" echo( popd exit /b :initColorPrint for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A" <nul >"%TEMP%\'" set /p "=." subst ': "%temp%" >nul exit /b :cleanupColorPrint 2>nul del "%temp%\'" 2>nul del "%temp%\colorPrint.txt" >nul subst ': /d exit /b input.bat Code: [Select]@echo off mode 20, 4 title input setlocal disableDelayedExpansion set user=kaka set messagev=message sent set "messagex=message fail" set downloadv=download finished set downloadx=download failed set donev=done set donex=failed set q=^" echo( call :c 02 "%messageV%" /n call :c 04 "%messagex%" /n call :c 02 "%downloadV%" /n call :c 04 "%downloadx%" /n call :c 02 "%doneV%" /n call :c 04 "%donex%" /n :loop set /p message= echo %user%: %message%>>chat.txt call :c 04 "%user%:"&call :c 0b "%message%" /n goto loop :c setlocal enableDelayedExpansion ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :colorPrint Color Str [/n] setlocal set "s=%~2" call :colorPrintVar %1 s %3 exit /b :colorPrintVar Color StrVar [/n] if not defined DEL call :initColorPrint setlocal enableDelayedExpansion pushd . ': cd \ set "s=!%~2!" :: The single blank line within the following IN() clause is critical - DO NOT REMOVE for %%n in (^"^ ^") do ( set "s=!s:\=%%~n\%%~n!" set "s=!s:/=%%~n/%%~n!" set "s=!s::=%%~n:%%~n!" ) for /f delims^=^ eol^= %%s in ("!s!") do ( if "!" equ "" setlocal disableDelayedExpansion if %%s==\ ( findstr /a:%~1 "." "\'" nul <nul set /p "=%DEL%%DEL%%DEL%" ) else if %%s==/ ( findstr /a:%~1 "." "/.\'" nul <nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%" ) else ( >colorPrint.txt (echo %%s\..\') findstr /a:%~1 /f:colorPrint.txt "." <nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" ) ) if /i "%~3"=="/n" echo( popd exit /b :initColorPrint for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A" <nul >"%temp%\'" set /p "=." subst ': "%temp%" >nul exit /b :cleanupColorPrint 2>nul del "%temp%\'" 2>nul del "%temp%\colorPrint.txt" >nul subst ': /d exit /b The only way I know of to make words diffrent colors on batch only works on Windows 7, and I don't quite understand it. Here is the code, It can't do special characters Code: [Select]@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" ) echo say the name of the colors, don't read call :ColorText 0a "blue" call :ColorText 0C "green" call :ColorText 0b "red" echo. call :ColorText 19 "yellow" call :ColorText 2F "black" call :ColorText 4e "white" pause goto :eof :ColorText echo off <nul set /p ".=%DEL%" > "%~2" findstr /v /a:%1 /R "^$" "%~2" nul del "%~2" > nul 2>&1 goto :eof Try this out (as it's own program) and SEE if it runs. You must include the loop at the top, and the :ColorText at the bottom (after the 'exit'). You will have to use a FOR /F to apply this to chat.txt.Quote The only way I know of to make words diffrent colors on batch only works on Windows 7, and I don't quite understand it. Here is the code, It can't do special characters Thanks for sharing this Lemonilla ... Just learned something new. With batch the color change use to always change all text on the display. And with old Basic the color x,y,z command use to change the entire lines color to whatever the last color call was prior to line return, which was slightly better, but never achieved the multiple colors on a single line until making websites with HTML..LOL Interesting that microsoft added this ability to command shell/batch. |
|