Thread: getting input from another program

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    155

    getting input from another program

    Hi, I am trying to get input from another program, text, then have my program use that to go on from there. How would you get the input from the other program tho? I tried but never got it to work by using "<iostream>" but I didnt get it to work right on my end b/c I only know how to get it from a file.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    just pipe the data to your program from the command prompt:

    C:\prompt> producer | consumer
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    Is there another way? I never did much with the command prompt, I do mean in c++ also. I am getting what I say from another program, not one I made.

  4. #4
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Create a windowless application, and then just get and parse whatever is given via the message loop

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    if the producer is sending it's output to stdout, you could use popen (often deprecated as _popen) to read the data from stdin using standard C calls (fgets, etc).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    You could use an intermediary process to create the two processes and monitor the sending / recieving data between both applications. There's another idea for you.

    You could create a file with this data you want to send (a temp file), and then have the second application read from that file. You could convert the data to a char array and just pass that data into the program (via the pipe operator Sebastiani was talking about, which I highly suggest you spend time -learning- that operator because it will save you an ungodly amount of time), and that will put it into the char *argv[] array, should be *argv[1] if I remember right. You could put the pathname of the temp file you created and pipe the pathname into *argv[1]. Basically...there's a ton of ways you could do this, each with their own special little advantages.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  7. #7
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    You could initiate the IInd program from the first and pass inputs as parameters to it. Theres some thing in the FAQ.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Utter newb?: Program crashes after input
    By deductible in forum C++ Programming
    Replies: 5
    Last Post: 12-13-2008, 10:27 PM
  3. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM
  4. provide input to another program
    By oncemyway in forum C Programming
    Replies: 14
    Last Post: 07-31-2005, 04:12 PM
  5. Input via the serial port for a C program
    By Anthony in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2005, 02:19 PM