56

I have a program which sends text to an LED sign.

prismcom.exe

To use the program to send "Hello":

prismcom.exe usb Hello

Now, I wish to, for example use a command program called Temperature.

temperature

Let's say the program gives your computer's temperature.

Your computer is 100 degrees Fahrenheit.

Now, I wish to write the output of temperature to prismcom.exe:

temperature | prismcom.exe usb

This does not seem to work.

Yes, I've looked for a solution to this for more than twenty minutes. In all cases, they are either kludges/hacks or a solution for something besides the Windows command line.

I would appreciate direction as to how I would pipe the output from temperature to prismcom.

Thanks!

Edit: Prismcom has two arguments. The first will always be 'usb'. Anything that comes after that will be displayed on the sign.

Austin Burk
  • 930
  • 4
  • 15
  • 33
  • 1
    If "temperature" is made to write to standard output and "prismcom" is made to read from standard input and write to standard output then this should Just Work. If not, you're probably out of luck. – 500 - Internal Server Error Jan 29 '13 at 01:27
  • prismcom has two arguments: usb; and then whatever comes after is sent to the sign. – Austin Burk Jan 29 '13 at 01:32
  • Could it be that temperature sends it's output to stderr rather than stdout? Try `temperature 2>&1 | prismcom usb` – rojo Jan 29 '13 at 02:17

4 Answers4

36

Try this. Copy this into a batch file - such as send.bat - and then simply run send.bat to send the message from the temperature program to the prismcom program.

temperature.exe > msg.txt
set /p msg= < msg.txt
prismcom.exe usb "%msg%"
Kenny Kerr
  • 3,015
  • 15
  • 18
18

This should work:

for /F "tokens=*" %i in ('temperature') do prismcom.exe usb %i

If running in a batch file, you need to use %%i instead of just %i (in both places).

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
17

You can also run exactly same command at Cmd.exe command-line using PowerShell. I'd go with this approach for simplicity...

C:\>PowerShell -Command "temperature | prismcom.exe usb"

Please read up on Understanding the Windows PowerShell Pipeline

You can also type in C:\>PowerShell at the command-line and it'll put you in PS C:\> mode instanctly, where you can directly start writing PS.

rautamiekka
  • 251
  • 2
  • 14
Ostati
  • 4,623
  • 3
  • 44
  • 48
  • 2
    That would pipe the standard output of `temperature` into the standard input of `prismcom`, wouldn't it? That's not what the question asks for; the output of `temperature` has to become one of the command-line arguments of `prismcom`. – Harry Johnston Feb 24 '18 at 03:38
  • @HarryJohnston In that case, in order for it to work, prismcom must implement the function of treating stdin the same way it treats the argument, musn't it? – Smart Humanism Mar 09 '23 at 06:03
-5

Not sure if you are coding these programs, but this is a simple example of how you'd do it.

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;
}

Compile both then run program1.exe "this subject has a submarine as a subsequence" | rgx.exe "\b(sub)([^ ]*)"

The | operator simply redirects the output of program1's printf operation from the stdout stream to the stdin stream whereby it's sitting there waiting for rgx.exe to pick up.

annoying_squid
  • 513
  • 5
  • 10