#include #include #include #include #include #include "d_exec.h" using namespace std; // ------------------------------------------------------------------------ d_exec::d_exec( void ) { // do nothing } // ------------------------------------------------------------------------ //d_exec::d_exec( string w ) //{ // char ss[1024]; // strcpy( ss, w.c_str() ); // // this->prun( ss ); //} /// ------------------------------------------------------------------------ //d_exec::d_exec( char *w ) //{ // this->prun( w ); //} //// ------------------------------------------------------------------------ void d_exec::prun( string w ) { char ss[1024]; strcpy( ss, w.c_str() ); this->prun( ss ); } // ------------------------------------------------------------------------ int d_exec::prun( const char *w ) { FILE *tr; char ch; string tmp; tr = popen( w, "r" ); //cout << "errno = " << errno << endl; //if( tr == NULL ) //{ // cout << "fork or pipe failed or can't allocate memory" << endl; // return( 0 ); //} //if( tr == -1 ) //{ // cout << "wait4 returned an error, or something else went wrong" << endl; // return( 0 ); //} while( !feof(tr) ) { ch = fgetc( tr ); if( ch == '\n' ) { if( !feof(tr) ) { data.push_back( tmp ); tmp = ""; } } else { if( !feof(tr) ) tmp += ch; } } if( tmp.size() > 0 ) { data.push_back( tmp ); } pclose( tr ); //cout << "errno = " << errno << endl; return( 0 ); } // ------------------------------------------------------------------------ //void d_exec::spit( void ) ostream &operator<<( ostream &out, const d_exec &L ) { int i; for( i = 0; i < L.data.size(); i++ ) { //cout << i << "\t" << data[i] << endl; out << i << " =\t" << L.data[i] << endl; } return( out ); } // ------------------------------------------------------------------------