proj home

Files   Classes   Functions   Hierarchy  

systemcalls.cpp

Go to the documentation of this file.
00001 #include <cstdlib>
00002 #include <iostream>
00003 #include <fstream>
00004 #include <vector>
00005 using namespace std;
00006 
00007 #include <commandline.h>
00008 #include <stringserialization.h>
00009 #include <systemcalls.h>
00010 #include <typedefs.h>
00011 
00012 stringc systemcalls::output() const
00013 {
00014   if (filename.empty())
00015     return "";
00016 
00017   string str;
00018   
00019   bool res=filestring::serialize(str,filename);
00020   if (res==false)
00021     return "";
00022 
00023   return str;
00024 }
00025 
00026 systemcalls::systemcalls
00027 (
00028   stringc & command_,
00029   stringc & filename_ 
00030 )
00031   : command(command_), filename(filename_) 
00032 {
00033   file_remove=true;
00034   combine=false;
00035 }
00036 
00037 // 
00038 int systemcalls::eval()
00039 {
00040   lines.clear();
00041 
00042 //stacktrace
00043 //cout << SHOW3(command) << endl;
00044 
00045   // Remove the file first before writing to it.
00046   if (file_remove==true)
00047   {
00048     string s0 = "if [ -e " + filename + " ]; then rm " + filename + "; fi";
00049     system(s0.c_str());
00050   }
00051 
00052   string s1(command);
00053   s1 += " > ";
00054   s1 += filename;
00055   // <cmd> > tempfile.txt
00056 
00057   if (combine)
00058     s1 +=  " 2>&1";
00059   // <cmd> > tempfile.txt 2>&1
00060   
00061 //cout << SHOW(s1.c_str()) << endl;
00062   exitstatus = system(s1.c_str());
00063   flush(cout);
00064   //cout << endl; // flush the buffer stream.
00065 
00066 //stacktrace
00067 //cout << SHOW3(exitstatus) << endl;
00068 
00069   ifstream in(filename.c_str());
00070   string str;
00071   while (in)
00072   {
00073     getline(in,str);
00074     if (str.length() > 0)
00075       lines.push_back(str);
00076   }
00077 
00078   return exitstatus;
00079 }
00080 
00081 systemcallseval::systemcallseval
00082 (
00083   stringc& command, 
00084   stringc& options
00085 )
00086   : systemcalls(command)
00087 {
00088   commandline cmd(options);
00089   cmd.mapvar(file_remove,"file_remove");
00090   cmd.mapvar(combine,"combine");
00091   
00092   eval();
00093 }
00094 
00095 
00096 
00097 
00098 
00099 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8