I have a string array of 3 different command line commands. Instead of writing out 3 system functions I am trying to learn how to pass a string array that holds these commands to the system function (or a similar function i.e. exec()) in a for loop. I am having trouble trying to figure out how to pass this string array into the system function one at a time. The goal is to get to exit status of each one and to break the for loop if returning an error.
std::string arrString[3] = {"something","another thing","a final thing"}
int i;
for(i=0; i<3; i++)
{
if (system(/*Something*/))
;//Do something...
}
EDIT: This outputs that an error happened, but it shouldn't.
std::string arrString[4] = {"cmd","cmd","cmd"};
int i;
for(i=0; i<3; i++)
{
if (system(arrString[i].c_str())==0) {
OutputDebugStringW(L"It works!");
}
else
{
OutputDebugStringW(L"It doesnt work :(");
}
}