简体   繁体   English

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

[英]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.

相关问题 在Windows命令提示符下,如果没有输入,如何在一定时间内运行一个命令,如果没有输入,又如何运行? - In Windows Command prompt, how can I run one command if there is no input, and another if there is, within a certain time? 我们如何打开多个终端以在 windows 上的 C 中显示 output? - How can we open multiple terminals for showing the output in C on windows? Python - 如何在脚本运行时隐藏 Windows 命令提示符屏幕? - Python - how can i hide the windows command prompt screen when the script is running? 如何将Windows命令提示符下发出的命令的Perl脚本输出重定向到文本文件 - How to redirect the Perl script output from command issued in windows command prompt to text file 我不知道如何通过 windows 命令提示符输入 - I don't know how to input through windows command prompt 无法在Windows命令提示符(cmd.exe)中重定向输出消息 - unable to redirect output message in windows command prompt (cmd.exe) 如何使用管道将一个命令的输出重定向到另一个命令的输入? - How do I use a pipe to redirect the output of one command to the input of another? 如何更改 Windows 命令提示符中的文本颜色 - How can I change the text color in the windows command prompt 如何在命令中使用文件并将 output 重定向到同一个文件而不截断它(Windows)? - How can I use a file in a command and redirect output to the same file without truncating it (Windows)? 如何在Windows(7)命令提示符中导出命令的历史记录? - How I can export the history of my commands in Windows(7) Command Prompt?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM