1.

Solve : output on second batch?

Answer»

hi all
i need your suggestion

there are 2 batch window open...

i enter text in first batch...and the text out on 2nd batch...

first batch look like
_____________________________________

hellooo

hahhaha

_
_____________________________________

2nd batch i want to look like
_____________________________________

user: hellooo

user: hahhaha
_____________________________________


how can i make text in first batch appear on 2nd batch?

this code i MADE so far...
first batch
Code: [Select]@echo off
mode 20, 4

title taip in
color 02

:loop
set /p message=

goto loop


2nd batch
Code: [Select]@echo off
mode 20, 32
setlocal disableDelayedExpansion
set user=user

set q=^"
echo(
call :c 04 "%user%:"&call :c 0b "%message%" /n

I usually USE a file system type thing.

code I used on another project:
display.bat
Code: [Select]@echo off
title GHX ^| Chat
mode con cols=50 lines=10
cd ..
:loop
copy /Y chat\chat.txt chatb.txt >nul
cls
type chat\chat.txt
:loop2
fc chat\chat.txt chatb.txt >nul
if "%errorlevel%"=="1" goto loop
goto loop2
input.bat
Code: [Select]@echo off
mode con cols=50 lines=1
title GHX ^| Chat
if exist chat.txt del chat.txt
if not exist chat.txt echo Welcome to GHX chat system >>chat.txt
:main
cls
call :clearvar
cscript //nologo write.vbs
if not exist chat.txt (
ping 127.0.0.1 >nul
goto main
)
set /p tosend=<write.txt
del write.txt
if "%tosend%"=="" goto main
echo %computername% ^:^: %tosend%>>chat.txt
if "%tosend%"=="::cls" (
del chat.txt
echo %computername% cleared the screen >>chat.txt
)
call :send
goto main

:clearvar
set tosend=
goto :eof

:send
if "%computername%"=="COMPAQ-3" robocopy "%cd%" "\\gearhead1189\shareddocs\ghx\chat" *.* /s /e >nul
if "%computername%"=="GEARHEAD1189" robocopy "%cd%" "\\compaq-3\shareddocs\ghx\chat" *.* /s /e >nul
goto :eof
write.vbs To remove special characters that could CRASH the program
Code: [Select]dim text
Wscript.Stdout.Write(">")
Wscript.StdIn.Read(0)
text = Wscript.StdIn.Readline()

Set RegEx = New RegExp

RegEx.Global = True
RegEx.IgnoreCase = False
RegEx.Pattern = "[^A-Za-z0-9: ]"

Set colMatches = RegEx.Execute(text)
If colMatches.Count <> 0 Then
WScript.Echo "Special Characters Found"
Else
set fso = CreateObject("Scripting.FileSystemObject")
'-filename
'-2 = writing
'-1 = reading
'-8 = appending
'-true = create if not exist
set fl = fso.OpenTextFile("C:\Documents and Settings\All Users\Documents\ghx\chat\write.txt", 2, True)
fl.Write(text)
fl.Close : Set fl = Nothing
Set fso = Nothing
end if

This might not work quite the way you want it to, but it should be at least something to look at. This was written for 2 Windows XP computers on a network (COMPAQ-3 and GEARHEAD1189)

It is a little easyer to do if you want it to only refresh on enter/chat. You can then condense it to 1 file.

Code: [Select]@echo off
:loop
cls
if exist chat.txt type chat.txt
echo.
set /p tosend=^>
echo %tosend% >>chat.txt
goto loop

For the username thing, you might want to look into 'for /f' to remove it from each line, so the file actually has both usernames, but only displays the one that isn't it's.
Code: [Select]for /f "tokens=1,2 delims=:" %%A in (chat.txt) do (
if "%%A"=="%username%" ( echo %%B
) else (
echo %%A : %%B
)
file:
Code: [Select]Name1:Message
Name1:Message
Name2:Message

Hope this helped at least a bit. Good luck on your project!ty
i learn something from yours code...but not all i can understand...

now i'm able to make text on input.bat display on display.bat
use

Quote

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

message1
massage2
massage3

and on display.bat show like this
Quote
kaka: message1
kaka: massage2
kaka: massage3
because its easy i want to make kaka different color
Quote
kaka: message1
kaka: message2
kaka: message3

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.


Discussion

No Comment Found