[英]Running two command prompt terminals in native windows, how can I redirect the output of one to the input of the other?
I have one Windows 10 command prompt running and awaiting input, and I wish to automate continuous and live input with a second command prompt. 我有一个运行中的Windows 10命令提示符,正在等待输入,我希望通过第二个命令提示符自动进行连续的实时输入。 I have gotten the second command prompt to extract the desired variable, and I wish to send it to the other command prompt that is waiting for input. 我已经获得了第二个命令提示符以提取所需的变量,并且希望将其发送到另一个等待输入的命令提示符。
The "awaiting input" command prompt must run in real time because it is connected to Plink (not an SSH session so no use of the -m command here) which is connecting to a microcontroller. “等待输入”命令提示符必须实时运行,因为它已连接到与微控制器连接的Plink(不是SSH会话,因此此处不使用-m命令)。 So it cannot be accomplished (at least I don't think) with function calls. 因此,无法通过函数调用来实现(至少我不认为)。
I see that it can be done in UNIX environments: https://askubuntu.com/questions/496914/write-command-in-one-terminal-see-result-on-other-one 我看到它可以在UNIX环境中完成: https : //askubuntu.com/questions/496914/write-command-in-one-terminal-see-result-on-other-one
Thanks in advance and please advise, 预先感谢,并请告知,
--A hopeful beginner -充满希望的初学者
Batch code starts 2 piped processes, one for getting keyboard input and writing to a file, and the other reading the data written. 批处理代码启动2个管道处理,一个用于获取键盘输入并写入文件,另一个用于读取写入的数据。 Note there isn't a cmd window for each process, but there are two new processes running. 请注意,每个进程都没有一个cmd窗口,但是正在运行两个新进程。 You may use cmd /c
or start
if you need two consoles. 您可以使用cmd /c
或在需要两个控制台的情况下start
。
Does it help? 有帮助吗?
@echo off
set "pipefile=pipefile.txt"
if "%~1" neq "" goto %1
copy nul "%pipefile%" >nul
"%~F0" getInput >>"%pipefile%" | "%~F0" readInput <"%pipefile%"
echo(
echo(Batch end...
ping localhost -n 1 >nul
del /F /Q "%pipefile%" 2>nul
exit/B
:getInput
set "input="
set/P "input="<CON
echo(%input%
if /I "%input%" equ "EXIT" exit
goto:getInput
:readInput
setlocal enableDelayedExpansion
set/P="enter some data [EXIT to exit] "
for /l %%. in () do (
set "input="
set/P "input="
if defined input (
if /I "!input!" equ "EXIT" exit
set/P="enter some data [EXIT to exit] "
)
ping 1.1.1.1 -w 10 -n 1 >nul 2>nul & rem avoid processor load (may be removed)
)
Running two console windows 运行两个控制台窗口
@echo off
set "pipefile=pipefile.txt"
if "%~1" neq "" goto %1
del /F /Q "%pipefile%" 2>nul
copy nul "%pipefile%" >nul
start "writer" cmd /c ^""%~f0" readInput ^<"%pipefile%" ^"
start "reader" cmd /c ^""%~f0" getInput ^"
echo(
Echo batch end...
ping localhost -n 1 >nul
goto :EOF
:getInput
set "input="
set/P "input=enter some data [EXIT to exit] "
echo(%input%>>"%pipefile%"
if /I "%input%" equ "EXIT" exit
goto:getInput
:readInput
setlocal enableDelayedExpansion
for /l %%. in () do (
set "input="
set /p "input="
if defined input (
if /I "!input!" equ "EXIT" exit
echo(!input!
)
ping 1.1.1.1 -w 10 -n 1 >nul 2>nul & rem avoid processor load (may be removed)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.