[英]Running two command prompt terminals in native windows, how can I redirect the output of one to the input of the other?
[英]How do I use a pipe to redirect the output of one command to the input of another?
我有一個程序將文本發送到LED標志。
prismcom.exe
要使用該程序發送“Hello”:
prismcom.exe usb Hello
現在,我希望使用一個名為Temperature的命令程序。
temperature
假設程序給出了計算機的溫度。
Your computer is 100 degrees Fahrenheit.
現在,我希望將溫度輸出寫入prismcom.exe:
temperature | prismcom.exe usb
這似乎不起作用。
是的,我已經找了20多分鍾的解決方案了。 在所有情況下,它們都是kludges / hacks或Windows命令行之外的解決方案。
我很欣賞如何將輸出從溫度傳輸到prismcom的方向。
謝謝!
編輯:Prismcom有兩個論點。 第一個將永遠是'usb'。 之后發生的任何事情都會顯示在標志上。
試試這個。 將其復制到批處理文件(例如send.bat)中,然后運行send.bat
將消息從溫度程序發送到prismcom程序。
temperature.exe > msg.txt
set /p msg= < msg.txt
prismcom.exe usb "%msg%"
這應該工作:
for /F "tokens=*" %i in ('temperature') do prismcom.exe usb %i
如果在批處理文件中運行,則需要使用%%i
而不僅僅是%i
(在兩個位置)。
您還可以使用PowerShell在Cmd.exe命令行上運行完全相同的命令。 為簡單起見,我會采用這種方法......
C:\>PowerShell -Command "temperature | prismcom.exe usb"
您也可以在命令行輸入C:\\>PowerShell
,它會立即進入PS C:\\>
模式,您可以直接開始編寫PS。
不確定您是否正在編寫這些程序,但這是一個如何執行此操作的簡單示例。
program1.c
#include <stdio.h>
int main (int argc, char * argv[] ) {
printf("%s", argv[1]);
return 0;
}
rgx.cpp
#include <cstdio>
#include <regex>
#include <iostream>
using namespace std;
int main (int argc, char * argv[] ) {
char input[200];
fgets(input,200,stdin);
string s(input)
smatch m;
string reg_exp(argv[1]);
regex e(reg_exp);
while (regex_search (s,m,e)) {
for (auto x:m) cout << x << " ";
cout << endl;
s = m.suffix().str();
}
return 0;
}
然后編譯兩個然后運行program1.exe "this subject has a submarine as a subsequence" | rgx.exe "\\b(sub)([^ ]*)"
program1.exe "this subject has a submarine as a subsequence" | rgx.exe "\\b(sub)([^ ]*)"
|
operator只是簡單地將program1的printf
操作的stdout
從stdout
流重定向到stdin
流,然后它就坐在那里等待rgx.exe接收。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.