5 * Created by Sarah Westcott on 7/8/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "systemcommand.h"
12 //**********************************************************************************************************************
13 vector<string> SystemCommand::setParameters(){
15 CommandParameter pcommand("command", "String", "", "", "", "", "",false,false); parameters.push_back(pcommand);
17 vector<string> myArray;
18 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
22 m->errorOut(e, "SystemCommand", "setParameters");
26 //**********************************************************************************************************************
27 SystemCommand::SystemCommand(string option) {
29 abort = false; calledHelp = false;
31 //allow user to run help
32 if(option == "help") { help(); abort = true; calledHelp = true; }
35 vector<string> myArray = setParameters();
37 OptionParser parser(option);
38 map<string, string> parameters = parser.getParameters();
39 map<string, string>::iterator it;
41 ValidParameters validParameter;
43 //check for optional parameter and set defaults
44 // ...at some point should added some additional type checking...
45 string commandOption = validParameter.validFile(parameters, "command", false);
46 if (commandOption == "not found") { commandOption = ""; }
47 else { command = commandOption; }
49 if ((option == "") && (commandOption == "")) { m->mothurOut("You must enter a command to run."); m->mothurOutEndLine(); abort = true; }
50 else if (commandOption == "") {
51 //check for outputdir and inputdir parameters
52 int commaPos = option.find_first_of(',');
54 //if there is a comma then grab string up to that pos
55 if (commaPos != option.npos) {
56 option = option.substr(0, commaPos);
65 m->errorOut(e, "SystemCommand", "SystemCommand");
69 //**********************************************************************************************************************
71 string SystemCommand::getHelpString(){
73 string helpString = "";
74 helpString += "The system command allows you to execute a system command from within mothur.\n";
75 helpString += "The system has no parameters.\n";
76 helpString += "The system command should be in the following format: system(yourCommand).\n";
77 helpString += "Example system(clear).\n";
81 m->errorOut(e, "SystemCommand", "help");
86 //**********************************************************************************************************************
88 int SystemCommand::execute(){
91 if (abort == true) { if (calledHelp) { return 0; } return 2; }
93 system(command.c_str());
99 m->errorOut(e, "SystemCommand", "execute");
104 //**********************************************************************************************************************