Main Page | Class List | File List | Class Members

command_line_program.h

Go to the documentation of this file.
00001 
00002 
00003 
00010 
00011 #ifndef SVEN_UI__COMMAND_LINE_PROG
00012 #define SVEN_UI__COMMAND_LINE_PROG
00013 
00014 #include <string>
00015 #include <sven/fs_addons.h>
00016 
00017 namespace sven_ui {
00018 
00019 //a wrapper for boost thread sleeping functions.
00020 void thread_sleep(double seconds);
00021 
00022 using std::string;
00023 using sven::cstring;
00024 
00025 namespace cmdline_prog_imp { struct CommandLineProgram; }
00026 
00034 struct CommandLineProgram {
00035 
00036 private:
00037         cmdline_prog_imp::CommandLineProgram * wrapped;
00038 
00039 public:
00040 
00041         CommandLineProgram();
00042         ~CommandLineProgram();
00043 
00044 
00046         void create_process(cstring name);
00047 
00048 
00052         void terminate_threads();
00053 
00055         void write_line(cstring s);
00056 
00058         string read();
00059         
00061         string read_error();
00062 
00064         bool process_is_dead(); 
00065 
00069         void finish();
00070 
00071 
00072         //
00073         // the following variables may be set prior to 
00074         // running start_process in order to tweak
00075         // various behaviors of the process and monitoring
00076         // threads.
00077         //
00078 
00079         double &read_tick;
00080         double &write_tick;
00081         double &finish_tick;
00082         double &finish_timeout;
00083 
00086         bool &seperate_std_error;
00087 
00090         bool &writeable;
00091 
00092         fs::wpath &starting_dir;                
00093 };
00094 
00095 
00097 inline string run_com(cstring com, double timeout=0) {
00098         CommandLineProgram prog;
00099         prog.finish_timeout=timeout;
00100         prog.writeable=false;
00101         prog.create_process(com);
00102         std::ostringstream rval;
00103         prog.finish();
00104         return prog.read();
00105 }
00106 
00107 }
00108 
00109 #endif

Generated on Mon Mar 17 12:13:59 2008 for Command Line Demo by  doxygen 1.3.9.1