]> git.donarmstrong.com Git - mothur.git/blob - systemcommand.cpp
added [ERROR] flag if command aborts
[mothur.git] / systemcommand.cpp
1 /*
2  *  systemcommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 7/8/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "systemcommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> SystemCommand::getValidParameters(){     
14         try {
15                 vector<string> myArray;
16                 return myArray;
17         }
18         catch(exception& e) {
19                 m->errorOut(e, "SystemCommand", "getValidParameters");
20                 exit(1);
21         }
22 }
23 //**********************************************************************************************************************
24 vector<string> SystemCommand::getRequiredParameters(){  
25         try {
26                 vector<string> myArray;
27                 return myArray;
28         }
29         catch(exception& e) {
30                 m->errorOut(e, "SystemCommand", "getRequiredParameters");
31                 exit(1);
32         }
33 }
34 //**********************************************************************************************************************
35 vector<string> SystemCommand::getRequiredFiles(){       
36         try {
37                 vector<string> myArray;
38                 return myArray;
39         }
40         catch(exception& e) {
41                 m->errorOut(e, "SystemCommand", "getRequiredFiles");
42                 exit(1);
43         }
44 }
45 //**********************************************************************************************************************
46
47 SystemCommand::SystemCommand(string option)  {
48         try {
49                 abort = false; calledHelp = false;   
50                 
51                 //allow user to run help
52                 if(option == "help") { help(); abort = true; calledHelp = true; }
53                 
54                 else {
55                         if (option == "") { m->mothurOut("You must enter a command to run."); m->mothurOutEndLine(); abort = true; }
56                         else { 
57                                 //check for outputdir and inputdir parameters
58                                 int commaPos = option.find_first_of(',');
59                                 
60                                 //if there is a comma then grab string up to that pos
61                                 if (commaPos != option.npos) {
62                                         option = option.substr(0, commaPos);
63                                 }
64                         
65                                 command = option;
66                         }
67                 }       
68
69         }
70         catch(exception& e) {
71                 m->errorOut(e, "SystemCommand", "SystemCommand");
72                 exit(1);
73         }
74 }
75 //**********************************************************************************************************************
76
77 void SystemCommand::help(){
78         try {
79                 m->mothurOut("The system command allows you to execute a system command from within mothur.\n");
80                 m->mothurOut("The system has no parameters.\n");
81                 m->mothurOut("The system command should be in the following format: system(yourCommand).\n");
82                 m->mothurOut("Example system(clear).\n");
83         }
84         catch(exception& e) {
85                 m->errorOut(e, "SystemCommand", "help");
86                 exit(1);
87         }
88 }
89
90 //**********************************************************************************************************************
91
92 int SystemCommand::execute(){
93         try {
94                 
95                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
96                 
97                 system(command.c_str());
98                 
99                 return 0;               
100         }
101
102         catch(exception& e) {
103                 m->errorOut(e, "SystemCommand", "execute");
104                 exit(1);
105         }
106 }
107
108 //**********************************************************************************************************************