two batch windows sync

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dani8190
Posts: 7
Joined: 17 Mar 2010 03:15

two batch windows sync

#1 Post by dani8190 » 17 Mar 2010 03:23

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: two batch windows sync

#2 Post by aGerman » 17 Mar 2010 13:32

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

dani8190
Posts: 7
Joined: 17 Mar 2010 03:15

Re: two batch windows sync

#3 Post by dani8190 » 17 Mar 2010 14:14

thank you so much

Post Reply