proj home

Files   Classes   Functions   Hierarchy  

systemcalls Class Reference

Primitive system calls. More...

#include <systemcalls.h>

Inheritance diagram for systemcalls:
Collaboration diagram for systemcalls:

List of all members.

Public Member Functions

 systemcalls (stringc &command_, stringc &filename_="/tmp/temp.txt")
 Construct everything at start.
int eval ()
 Evaluate the system call, saving the output to lines.
stringc output () const
 Output of command.

Public Attributes

bool file_remove
 Delete the existing file.
bool combine
 output and error messages combined
string command
 System command executed.
string filename
 Redirect output of system command to file for reading.
vector< string > lines
 Output from system command.


Detailed Description

Primitive system calls.

This is for integration with other programming languages. Generally programming languages do not talk to eachother, but most write to files. So we can use files to pass information between different applications, programs and programming languages.

Example
  systemcalls sys01("ls","temp.txt");
  sys01.eval();
  for (uint i=0; i<sys01.lines.size(); ++i)
    { cout << sys01.lines[i] << endl; };
Exit Codes http://en.wikipedia.org/wiki/Exit_status

Definition at line 31 of file systemcalls.h.


Constructor & Destructor Documentation

systemcalls::systemcalls ( stringc command_,
stringc filename_ = "/tmp/temp.txt" 
)

Construct everything at start.

Definition at line 27 of file systemcalls.cpp.

00031   : command(command_), filename(filename_) 
00032 {
00033   file_remove=true;
00034   combine=false;
00035 }


Member Function Documentation

int systemcalls::eval (  ) 

Evaluate the system call, saving the output to lines.

Definition at line 38 of file systemcalls.cpp.

References combine, command, exitint::exitstatus, file_remove, filename, and lines.

Referenced by mkerrorscompile::compilecode(), projfiles< CFC >::construct(), systemcallstest::developmenttest04(), projunittests::eval(), unittestcmd::eval(), mkerrorscompile::eval(), and systemcallstest::unittest01().

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 }

stringc systemcalls::output (  )  const

Output of command.

Definition at line 12 of file systemcalls.cpp.

References filename, and filestring::serialize().

Referenced by mkerrorscompile::compilecode(), projunittests::eval(), and unittestcmd::eval().

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 }


Member Data Documentation

output and error messages combined

Definition at line 42 of file systemcalls.h.

Referenced by mkerrorscompile::compilecode(), eval(), and unittestcmd::eval().

System command executed.

Definition at line 48 of file systemcalls.h.

Referenced by eval().

Delete the existing file.

Definition at line 39 of file systemcalls.h.

Referenced by eval().

Redirect output of system command to file for reading.

Definition at line 50 of file systemcalls.h.

Referenced by eval(), and output().

vector<string> systemcalls::lines

Output from system command.

Definition at line 53 of file systemcalls.h.

Referenced by projfiles< CFC >::construct(), systemcallstest::developmenttest04(), eval(), and systemcallstest::unittest01().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:18 2011 for Chelton Evans Source by  doxygen 1.5.8