Original batch file cmd window to other window jump
Moderator: DosItHelp
Original batch file cmd window to other window jump
Hi,
I want to write a batch file to operate another cmd prompt.
Can anyone tell how to jump control from one cmd to another such that the later lines in the batch file are executed in the other command prompt window.
I want to write a batch file to operate another cmd prompt.
Can anyone tell how to jump control from one cmd to another such that the later lines in the batch file are executed in the other command prompt window.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Original batch file cmd window to other window jump
Not sure why you'd want to do this, but you'd have to make separate sender and listener scripts that share a common file with the sender writing to it and the receiver reading from it every few seconds.
I could have sworn I posted something like this here a while ago but I can't seem to find it...
I could have sworn I posted something like this here a while ago but I can't seem to find it...
-
- Posts: 118
- Joined: 02 Apr 2017 06:11
Re: Original batch file cmd window to other window jump
This is extremely easy to do!
You'll have to make a datafile like : MyDataFile.Data
and then use echo to write the data in the datafile and then use For /f to extract the data from the file.
Original Batch File:
Batch File That receives the super important data :
Hope I helped!
You'll have to make a datafile like : MyDataFile.Data
and then use echo to write the data in the datafile and then use For /f to extract the data from the file.
Original Batch File:
Code: Select all
@echo off
Setlocal EnableDelayedExpansion
Set Data=MyDataFile.data
>!Data! (
Echo SuperImportantData
Echo EvenMoreSuperImportantData
Echo SuperSuperSuperSuperImportantData
)
Batch File That receives the super important data :
Code: Select all
@echo off
Setlocal EnableDelayedExpansion
Set Data=MyDataFile.data
For /f "tokens=*" %%A IN (!Data!) DO (
Set FirstLine=%%A
Set SecondLine=%%B
Set ThirdLine=%%C
::And so on!
)
Hope I helped!
Re: Original batch file cmd window to other window jump
you can use AppActivate function from windows shell application object from jscript or vbscript or powershell.
-
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: Original batch file cmd window to other window jump
this is an approch:
Open two command prompts in the same current directory,
On the server side,
On the client side,
When you enter a command here, it is executed on the server side and the result is displayed on the client side.
einstein1969
Open two command prompts in the same current directory,
On the server side,
Code: Select all
Call >0
Tail-f 0 | cmd 1>1 2>2
On the client side,
Code: Select all
Start /b tail-f 1
Start /b tail-f 2
Copy /y con 0
When you enter a command here, it is executed on the server side and the result is displayed on the client side.
einstein1969
Re: Original batch file cmd window to other window jump
@einstein1969 - What tail
I tried with gnu tail for Windows, and could not reproduce. I don't understand why you are having the server output appear on the client - I don't get that from the OP's request at all.
@rbbr000 - I've demonstrated how this can be done with pure batch at Send commands to a cmd window through a .bat file - Rejected StackOverflow question
Dave Benham
I tried with gnu tail for Windows, and could not reproduce. I don't understand why you are having the server output appear on the client - I don't get that from the OP's request at all.
@rbbr000 - I've demonstrated how this can be done with pure batch at Send commands to a cmd window through a .bat file - Rejected StackOverflow question
Dave Benham
-
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: Original batch file cmd window to other window jump
@Dave
for my experiment I have used a jscript implementation of tail -f.
tail-f.cmd
the step are:
- open cmd window 1
-open cmd window 2
This for output on window 2. But if windows 2 is started via taskscheduler (ie for execute privileged operation) the output may be redirected back to window 1 and then required 2 backgroung tail-f (look previuos post).
Onother implementation that I found for tail -f is this but there is a problem for order of startup for the version on previous post. Work well for this example.
tail-f.cmd
windows7
Einstein1969
for my experiment I have used a jscript implementation of tail -f.
tail-f.cmd
Code: Select all
@if(0)==(0) ECHO OFF
CScript.exe //NoLogo //E:JScript "%~f0" %1
GOTO :EOF
@end
var StdIn=new ActiveXObject('Scripting.FileSystemObject').OpenTextFile(WScript.Arguments.Item(0));
while(true) if(StdIn.AtEndOfStream) WScript.Sleep(1000);else WScript.StdOut.Write(StdIn.Read(4096));
the step are:
- open cmd window 1
Code: Select all
call >0
copy /y con 0
-open cmd window 2
Code: Select all
tail-f 0 | cmd
This for output on window 2. But if windows 2 is started via taskscheduler (ie for execute privileged operation) the output may be redirected back to window 1 and then required 2 backgroung tail-f (look previuos post).
Onother implementation that I found for tail -f is this but there is a problem for order of startup for the version on previous post. Work well for this example.
tail-f.cmd
Code: Select all
@ECHO OFF
SETLOCAL
IF NOT EXIST "%~1" (
ECHO Usage: %~nx0 file
GOTO :EOF
)
SET SS=0
SET LL=0
:TOP
IF %SS%==%~z1 (
rem SLEEP 1
ping localhost -n 2 >NUL
CMD /C "TYPE NUL>>%1" 2>NUL
IF NOT ERRORLEVEL 1 GOTO :EOF
GOTO :TOP
)
SET SS=%~z1
FOR /F "delims=[] tokens=1*" %%1 IN ('FIND /N /V "" ^<%1 ^|MORE +%%LL%%') DO (
SET LL=%%1
ECHO:%%2
)
GOTO :TOP
windows7
Einstein1969
Re: Original batch file cmd window to other window jump
Thanks.
My gnu version of tail does not work well because it buffers the output - nothing is written until the output buffer is full
Your strategy is basically the same as what I did in my linked post, except I am effectively implementing a pure batch version of tail -f
Dave Benham
My gnu version of tail does not work well because it buffers the output - nothing is written until the output buffer is full
Your strategy is basically the same as what I did in my linked post, except I am effectively implementing a pure batch version of tail -f
Dave Benham