Show
Ignore:
Timestamp:
26.05.2010 23:52:09 (10 years ago)
Author:
davidb
Message:

Further development of the os_process classes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/os_process.cpp

    r22173 r22177  
    2626#include "os_process.h" 
    2727 
    28 osprocess::osprocess(char* cmd) 
    29 {} 
    3028osprocess::osprocess(char* cmdline, OSProcessPipeMode mode) 
    3129  : mode_(mode) 
     
    3634} 
    3735   
    38 /* 
    39 bool osprocess::eop() 
     36bool osprocess::close() 
    4037{ 
     38  // close any file handles that are still open 
     39 
     40  bool write_close_rv = close_write_pipe(withoutWarning); 
     41  bool read_close_rv = close_read_pipe(withoutWarning); 
     42 
     43  return (write_close_rv && read_close_rv); 
    4144} 
    4245 
    43 bool osprocess::eop(OSProcessPipeMode) 
     46 
     47 
     48 
     49#if 1 
     50 
     51#include "os_process_windows.h" 
     52#include "os_process_unix.h" 
     53#include <iostream> 
     54using namespace std; 
     55 
     56void test_uni_write_pipe() 
    4457{ 
     58#ifdef __WIN32__ 
     59  char* prog_name = "c:\\Windows\\system32\\java.exe"; 
     60  char* cmd_line = "java"; 
     61   
     62  //char* input_line = "echo hi there\n"; 
     63  //char* prog_name  = "c:\\cygwin\\bin\\cat.exe"; 
     64  //char* cmd_line   = "cat"; 
     65#else 
     66  char* cmd_line = "/usr/bin/java"; 
     67  //char* cmd_line = "java"; 
     68#endif 
     69 
     70#ifdef __WIN32__ 
     71  osprocesswindows* process = new osprocesswindows(cmd_line,uniRead); 
     72#else 
     73  osprocessunix* process = new osprocessunix(cmd_line,uniRead); 
     74#endif 
     75   
     76  const int BufferSize = 1024; 
     77  char buffer[BufferSize]; 
     78 
     79  int bytes_read = 0; 
     80  do { 
     81    bytes_read = process->read(buffer,BufferSize); 
     82    if (bytes_read>0) { 
     83      fwrite(buffer,1,bytes_read,stdout); 
     84    } 
     85  } while (bytes_read==BufferSize); 
     86 
     87 
     88  delete process; 
     89 
    4590} 
    46 */ 
    4791 
    48 int osprocess::read(char* buffer, const int buffer_len) 
     92int main() 
    4993{ 
     94  printf("Content-type: text/html\n\n"); 
     95   
     96  printf( "<html>\n"); 
     97  printf( "  <head>\n"); 
     98  printf( "    <title>Testing</title>\n"); 
     99  printf( "  </head>\n"); 
     100  printf( "  <body>\n"); 
     101 
     102  test_uni_write_pipe(); 
     103 
     104  printf( "  </body>\n"); 
     105  printf( "</html>\n"); 
     106   
    50107  return 0; 
    51108} 
    52109 
    53 int osprocess::write(char* buffer, const int buffer_len) 
    54 { 
    55   return 0; 
    56 } 
    57    
    58 bool osprocess::close()  
    59 { 
    60   return true; 
    61 } 
     110#endif 
    62111 
    63 bool osprocess::close(OSProcessPipeMode mode) 
    64 { 
    65   return true; 
    66 } 
    67