5 * Created by Sarah Westcott on 7/8/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "systemcommand.h"
12 //**********************************************************************************************************************
14 SystemCommand::SystemCommand(string option){
18 //allow user to run help
19 if(option == "help") { help(); abort = true; }
22 //valid paramters for this command
23 string Array[] = {"command"};
24 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
26 OptionParser parser(option);
27 map<string,string> parameters = parser.getParameters();
29 ValidParameters validParameter;
31 //check to make sure all parameters are valid for command
32 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
33 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
36 //check for required parameters
37 command = validParameter.validFile(parameters, "command", false);
38 if (command == "not found") { mothurOut("command is a required parameter."); mothurOutEndLine(); abort = true; }
43 errorOut(e, "SystemCommand", "SystemCommand");
47 //**********************************************************************************************************************
49 void SystemCommand::help(){
51 mothurOut("The system command allows you to execute a system command from within mothur.\n");
52 mothurOut("The system command parameter is command and it is required.\n");
53 mothurOut("The system command should be in the following format: system(command=yourCommand).\n");
54 mothurOut("Example system(command=clear).\n");
55 mothurOut("Note: No spaces between parameter labels (i.e. command), '=' and parameters (i.e.yourCommand).\n\n");
58 errorOut(e, "SystemCommand", "help");
63 //**********************************************************************************************************************
65 int SystemCommand::execute(){
68 if (abort == true) { return 0; }
70 system(command.c_str());
76 errorOut(e, "SystemCommand", "execute");
81 //**********************************************************************************************************************