getting input from another program

This is a discussion on getting input from another program within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to get input from another program, text, then have my program use that to go on ...

  1. #1
    adr
    adr is offline
    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,655
    just pipe the data to your program from the command prompt:

    C:\prompt> producer | consumer

  3. #3
    adr
    adr is offline
    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,655
    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).

  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, 02:30 PM
  2. Utter newb?: Program crashes after input
    By deductible in forum C++ Programming
    Replies: 5
    Last Post: 12-13-2008, 09:27 PM
  3. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 05: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21