]> git.donarmstrong.com Git - mothur.git/blob - systemcommand.cpp
added set.dir command and modified commands to redirect input and output, removed...
[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;
17                 
18                 //allow user to run help
19                 if(option == "help") { help(); abort = true; }
20                 
21                 else {
22                         if (option == "") { mothurOut("You must enter a command to run."); 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                 errorOut(e, "SystemCommand", "SystemCommand");
39                 exit(1);
40         }
41 }
42 //**********************************************************************************************************************
43
44 void SystemCommand::help(){
45         try {
46                 mothurOut("The system command allows you to execute a system command from within mothur.\n");
47                 mothurOut("The system has no parameters.\n");
48                 mothurOut("The system command should be in the following format: system(yourCommand).\n");
49                 mothurOut("Example system(clear).\n");
50         }
51         catch(exception& e) {
52                 errorOut(e, "SystemCommand", "help");
53                 exit(1);
54         }
55 }
56
57 //**********************************************************************************************************************
58
59 int SystemCommand::execute(){
60         try {
61                 
62                 if (abort == true) { return 0; }
63                 
64                 system(command.c_str());
65                 
66                 return 0;               
67         }
68
69         catch(exception& e) {
70                 errorOut(e, "SystemCommand", "execute");
71                 exit(1);
72         }
73 }
74
75 //**********************************************************************************************************************