]> git.donarmstrong.com Git - mothur.git/blob - systemcommand.cpp
removed read.dist, read.otu, read.tree and globaldata. added current to defaults...
[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 //**********************************************************************************************************************
14 SystemCommand::SystemCommand(string option)  {
15         try {
16                 abort = false; calledHelp = false;   
17                 
18                 //allow user to run help
19                 if(option == "help") { help(); abort = true; calledHelp = true; }
20                 
21                 else {
22                         if (option == "") { m->mothurOut("You must enter a command to run."); m->mothurOutEndLine(); abort = true; }
23                         else { 
24                                 //check for outputdir and inputdir parameters
25                                 int commaPos = option.find_first_of(',');
26                                 
27                                 //if there is a comma then grab string up to that pos
28                                 if (commaPos != option.npos) {
29                                         option = option.substr(0, commaPos);
30                                 }
31                         
32                                 command = option;
33                         }
34                 }       
35
36         }
37         catch(exception& e) {
38                 m->errorOut(e, "SystemCommand", "SystemCommand");
39                 exit(1);
40         }
41 }
42 //**********************************************************************************************************************
43
44 string SystemCommand::getHelpString(){
45         try {
46                 string helpString = "";
47                 helpString += "The system command allows you to execute a system command from within mothur.\n";
48                 helpString += "The system has no parameters.\n";
49                 helpString += "The system command should be in the following format: system(yourCommand).\n";
50                 helpString += "Example system(clear).\n";
51                 return helpString;
52         }
53         catch(exception& e) {
54                 m->errorOut(e, "SystemCommand", "help");
55                 exit(1);
56         }
57 }
58
59 //**********************************************************************************************************************
60
61 int SystemCommand::execute(){
62         try {
63                 
64                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
65                 
66                 system(command.c_str());
67                 
68                 return 0;               
69         }
70
71         catch(exception& e) {
72                 m->errorOut(e, "SystemCommand", "execute");
73                 exit(1);
74         }
75 }
76
77 //**********************************************************************************************************************