Page 1 of 1

two batch windows sync

Posted: 17 Mar 2010 03:23
by dani8190
is it possible to sync two cmd windows?
there is two cmd windows open.
when i typing in window1 and press enter.
the message will popup in window2.
how to do that

Re: two batch windows sync

Posted: 17 Mar 2010 13:32
by aGerman
There is no real good possibility for such an intention. The first batch have to write to a file and the second batch have to read this file using an endless loop.

1.bat

Code: Select all

@echo off &setlocal
type nul>"data.txt"
echo Enter your text:
echo.
:loop
set "input="
set /p "input="
>>"data.txt" echo.%input%
goto loop


2.bat

Code: Select all

@echo off &setlocal
set /a n1=0
set /a n2=0
:loop
if not exist "data.txt" (
  cls
  set /a n1=0
  set /a n2=0
  ping -n 2 localhost>nul
  goto loop
)
for /f "delims=: tokens=1*" %%a in ('findstr /n /r /c:"^" "data.txt"') do (
  set /a n1=%%a
  set "line=%%b"
  call :process
)
ping -n 2 localhost>nul&goto loop
goto:eof

:process
if %n1% gtr %n2% (
  set /a n2=%n1%
  echo.%line%
)
goto :eof

Re: two batch windows sync

Posted: 17 Mar 2010 14:14
by dani8190
thank you so much