To build a string with all the concatenated arguments, and then run the command based on these arguments, you can use something like:
#include <string> using namespace std; string concatenate ( int argc, char* argv[] ) { if (argc < 1) { return ""; } string result(argv[0]); for (int i=1; i < argc; ++i) { result += " "; result += argv[i]; } return result; } int main ( int argc, char* argv[] ) { const string arguments = concatenate(argc-1, argv+1); if (arguments == "/all /renew") { const string program = "c:\\windows\\system32\\ipconfig.exe"; const string command = program + " " + arguments; system(command.c_str()); } else { system("\"\"c:\\program files\\internet explorer\\iexplore.exe\" \"www.stackoverflow.com\"\""); } }
source share