0

I need to control a program in c++ (windows), I need to call it, then pass data to it as I collect it, finally after a certain command that program will use that data.

I need to open the prog.exe and then line by line or value by value supply it information, it works manually through cmd.

I have tried system() but this will stop after I open the program.

I need something like this.

//call it
prog.exe
//add data
DataStart
Data 1 [2 34 454 5]//etc
DataEnd //the program will take it from here.

all being passed though command line

tshepang
  • 12,111
  • 21
  • 91
  • 136
t_s
  • 1
  • 2
    Just read from standard input. –  Jul 07 '10 at 17:24
  • Do you mean, `prog.exe` would read data from standard input? You probably mean that. – Amadan Jul 07 '10 at 17:25
  • 1
    Not quite a duplicate of http://stackoverflow.com/questions/450865/what-is-the-equivalent-to-posix-popen-in-the-win32-api but the answers should be useful. – sarnold Jul 07 '10 at 17:30

2 Answers2

1

There are different ways you could do this - if your program needs to execute part of the way through your code before getting the data as input, you can just use standard input, and prompt the user to type the data. If you want to use variable values for the input, but you will know them before execution, you can pass the information as command line arguments, where you will execute like so

prog.exe 1 2 3

and your program will access the data via argv[i] where i corresponds to each command line argument.

xdumaine
  • 10,096
  • 6
  • 62
  • 103
  • sorry if i have put this reply in the wrong section. I do not know any of the values so i cannot parze the command line. by calling the program, it starts in the shell, it will then except user inputs as its variables etc. the program accepting these inputs is not mine i am wanting to input these variables, however then need to be queried each time. i need to stat the prog and leave access to it so i can add this data as it is quried. – t_s Jul 07 '10 at 18:40
0

have your program read from standard input, and from the command line 'pipe' the result of the other program to yours

eg.

datagenerator.exe | prog.exe

assuming that datagenerator.exe writes to standard output, the | character will redirect the output to prog.exe's standard input

Lefteris E
  • 2,806
  • 1
  • 24
  • 23