繁体   English   中英

在本机窗口中运行两个命令提示符终端,如何将一个输出重定向到另一个输入?

[英]Running two command prompt terminals in native windows, how can I redirect the output of one to the input of the other?

我有一个运行中的Windows 10命令提示符,正在等待输入,我希望通过第二个命令提示符自动进行连续的实时输入。 我已经获得了第二个命令提示符以提取所需的变量,并且希望将其发送到另一个等待输入的命令提示符。

“等待输入”命令提示符必须实时运行,因为它已连接到与微控制器连接的Plink(不是SSH会话,因此此处不使用-m命令)。 因此,无法通过函数调用来实现(至少我不认为)。

我看到它可以在UNIX环境中完成: https//askubuntu.com/questions/496914/write-command-in-one-terminal-see-result-on-other-one

预先感谢,并请告知,

-充满希望的初学者

批处理代码启动2个管道处理,一个用于获取键盘输入并写入文件,另一个用于读取写入的数据。 请注意,每个进程都没有一个cmd窗口,但是正在运行两个新进程。 您可以使用cmd /c或在需要两个控制台的情况下start

有帮助吗?

@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) 
)

运行两个控制台窗口

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM