Program to execute another Program with Command line arguments

I want to call a program with command line arguments (eg p1.exe arg1 arg2) from a C++ program. Does anyone know how? Thanks.
To be more specific,

I am reading values of CUSIP from the file, in a loop and and calling program.exe with different values of CUSIP each time, until EOF.

 
 rv = system("program.exe CUSIP");


Above code will pass hardcoded CUSIP and not its value. How do I pass values of CUSIP?
closed account (S6k9GNh0)
Like C and many others, the main function that starts a process allows two parameters or no parameters to be passed. The two parameters that may be passed are an integer and a two-dimensional array of char and looks like: int main(int argc, char ** argv). Though argc and argv are often what they are called, they may be named anything you want them to be called since your implementing the function. A common example is like this:

1
2
3
4
5
6
7
8
9
#include <iostream>

int main(int argc, char ** argv)
{
   if (argc > 1 && argc < 3)
      std::cout << argv[1] << std::endl;

   std::cin.get();
}


To add to this, the example given is an EXTREMELY unsafe and non-standard method of going about things. I really do suggest you make a library and call functions with parameters from that or you implement it into your current executable / library.
Last edited on
This is not what I am asking. I want to make a function call (alongwith Command line arguments) from within a C++ program.
You mean something like this?
1
2
3
std::stringstream stream;
stream <<"program.exe "<<cusip;
system(stream.str().c_str());
Yes, thats how I finally solved it (I used sprintf though). Thanks!
Topic archived. No new replies allowed.