/* * launch.cpp * Benjamin Bertka - 23306103 * bbertka@mss.icics.ubc.ca * * CICS505 - os6 partA */ #include "windows.h" #include #include #include #include "MyProcess.h" /* * This program reads windows application executables * from a text file and executes each one in sequence. */ using namespace std; /* * Creates a MyProcess process to execute a specific command * @param cmd - The command to execute * PRE: command is a valid command * POST: return true if process was successfully created * or returns false if there was a problem */ bool doProcess(string cmd){ MyProcess process2; process2.setTitle(const_cast(cmd.c_str())); process2.setCommand(const_cast(cmd.c_str())); if(!process2.create()){ cout << "Error: could not execute: " << cmd << endl; return false; } process2.print(); process2.wait(); process2.close(); return true; } /* * Reads a textfile containing commands to execute * and sends each command for process creation * @param list - the list of commands * PRE: the list of commands has something in it * POST: returns true if all comands executed * or returns false if one command had a problem */ bool readProcessList(char* list){ char command[256]; ifstream ifs (list, ifstream::in); for( int i = 0; ifs.good(); ++i){ ifs.getline(command, 256); string str = command; if(str.size() > 1){ if(!doProcess(str)){ return false; } } } return true; } /* * the main entry poin to this program * reads command list from user, and * sends the list to be processed and commands executed * @param argv[1] - the list of commands * PRE: the list of commands is valid and readable * POST: prints eror message if a problem with methods * defined above. */ int main(int argc, char **argv){ if(argc != 2){ cout << "Error. Not enough args." << endl; cout << "Usage: launch.exe [list.txt]" << endl; return 1; }else if(!readProcessList(argv[1])){ cout << "Error. Bad list format." << endl; cout << "Usage: launch.exe [list.txt]" << endl; return 1; } return 0; }