Thread: Reading data from other programs

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Reading data from other programs

    I don't know if what I want is possible, so if it isn't, just tell me. I have a program someone has written in visual basic, the program basically just generates random numbers. What I want to do is write a program that can read these numbers, so I can compare them i.e. if the number from the program is bigger than some other number then do this.

    Thanks in advance for any help.

  2. #2
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    That seems like adding extra work for no reason, why not just incorporate the program into yours? Have your program generate a random number on it's own and then compare it to that, makes it alot easier.
    If you want to read from the file, the only way I know how to do it is to have a .dat file, then using fstream use fin to read the number, then initilize a varible to that value... hope that made sense.
    If you ever need a hug, just ask.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You can either pipe the output of the VB program into your C++ program via the command line mechanism:
    Code:
    recv | send
    Or you can open a pipe inside your C program with an implementation defined function such as popen.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    3
    OK, the visual basic program does more than generate random numbers, but thats the only bit im interested in. I don't have the source for the VB program as it was written by someone else, so I'm not sure if I can use a pipe.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    > I don't have the source for the VB program as it was written by someone else, so I'm not sure if I can use a pipe.
    You don't need source, just an executable file the produces output to standard output.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    3
    Ok, as you probably noticed im a newbie to this, could someone show me an example of a pipe in use? I don't know if the executable i have (from the VB prog.) produces standard output, is there anyway I can find out? I was also wondering if it was possible for the c/++ prog. to create something like a box, and then put the box around the random number (the random number shows up on the screen) and then it could read what the number was, is anything like that possible or not? Thanks for the help so far.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I don't know if the executable i have (from the VB prog.) produces standard output, is there anyway I can find out?
    Yes, run it on the command line. If you see the output then that's what you want.

    >could someone show me an example of a pipe in use?
    I already have, on the command line do this:
    Code:
    $ cprog | vbprog
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading large complicated data files
    By dodzy in forum C Programming
    Replies: 16
    Last Post: 05-17-2006, 04:57 PM
  2. reading formatted data files
    By gL_nEwB in forum C++ Programming
    Replies: 5
    Last Post: 04-22-2006, 10:09 PM
  3. accessing my com port, writing and reading data
    By shoobsie in forum C Programming
    Replies: 7
    Last Post: 09-16-2005, 03:29 PM
  4. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  5. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM