Changeset 22188 for main/trunk/greenstone2/runtime-src/src
- Timestamp:
- 2010-05-27T23:56:02+12:00 (14 years ago)
- Location:
- main/trunk/greenstone2/runtime-src/src/recpt
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/recpt/os_process.cpp
r22187 r22188 46 46 47 47 48 49 50 #if 051 52 #include "os_process_windows.h"53 #include "os_process_unix.h"54 #include <iostream>55 using namespace std;56 57 58 59 void test_uni_write_pipe()60 {61 #ifdef __WIN32__62 char* prog_name = "type";63 char* argv[] = { "type", NULL } ;64 65 #else66 char* prog_name = "tr";67 char* argv[] = { "tr", "[A-Z]", "[a-z]", NULL };68 #endif69 70 cout << "<hr>" << endl;71 cout << "<p>Unidirectional Write Test" << endl;72 cout << "<p> Converts uppercase letters to lowercase" << endl;73 cout << "<p> These are then sent to whereever the stdout of the child process goes" << endl;74 cout << "<p>" << endl;75 76 #ifdef __WIN32__77 osprocesswindows* process = new osprocesswindows(uniWrite,prog_name,argv);78 #else79 osprocessunix* process = new osprocessunix(uniWrite,prog_name,argv);80 #endif81 82 char* buffer = "TESTING uniWirite IN CAP\nTesting uniWrite in Mixed Case\n";83 int buffer_len = strlen(buffer);84 85 if (!process->write(buffer,buffer_len)) {86 cerr << "Error: failed to write to child process\n";87 }88 89 process->close();90 91 process->wait();92 93 delete process;94 }95 96 97 void test_uni_read_pipe()98 {99 char* prog_name = "java";100 char* argv[] = { "java", NULL };101 102 cout << "<hr>" << endl;103 cout << "<p>Unidirectional Read Test" << endl;104 cout << "<p> The output of 'java' is read in by this process and then sent to stdout" << endl;105 cout << "<p>" << endl;106 107 108 #ifdef __WIN32__109 osprocess* process = new osprocesswindows(uniRead,prog_name,argv);110 #else111 osprocess* process = new osprocessunix(uniRead,prog_name,argv);112 #endif113 114 const int BufferSize = 1024;115 char buffer[BufferSize];116 117 int bytes_read = 0;118 do {119 bytes_read = process->read(buffer,BufferSize);120 if (bytes_read>0) {121 fwrite(buffer,1,bytes_read,stdout);122 }123 } while (bytes_read==BufferSize);124 125 126 // deleting object will also have the effect of closing any open handles127 delete process;128 129 }130 131 132 133 void test_bi_read_write_pipe()134 {135 #ifdef __WIN32__136 char* prog_name = "type";137 char* argv[] = NULL ;138 139 #else140 char* prog_name = "tr";141 char* argv[] = { "tr", "[A-Z]", "[a-z]", NULL };142 #endif143 144 // Converts uppercase letters to lowercase145 // Answer is read back and then printed to STDOUT by this process146 147 cout << "<hr>" << endl;148 cout << "<p>Bidirectional Read/Write Test" << endl;149 cout << "<p> Converts uppercase letters to lowercase" << endl;150 cout << "<p> Data is sent to child process down pipe by this process" << endl;151 cout << "<p> Answer is read back from child process and printed to stdout" << endl;152 cout << "<p>" << endl;153 154 #ifdef __WIN32__155 osprocesswindows* process = new osprocesswindows(biReadWrite,prog_name,argv);156 #else157 osprocessunix* process = new osprocessunix(biReadWrite,prog_name,argv);158 #endif159 160 char* write_buffer = "TESTING biReadWrite IN CAP\nTesting biReadWrite in Mixed Case\n";161 int write_buffer_len = strlen(write_buffer);162 163 if (!process->write(write_buffer,write_buffer_len)) {164 cerr << "Error: failed to write to child process\n";165 }166 167 const int BufferSize = 1024;168 char read_buffer[BufferSize];169 process->close_write_pipe();170 171 int bytes_read = 0;172 do {173 bytes_read = process->read(read_buffer,BufferSize);174 if (bytes_read>0) {175 fwrite(read_buffer,1,bytes_read,stdout);176 }177 } while (bytes_read==BufferSize);178 179 180 process->close();181 182 delete process;183 184 }185 186 187 int main()188 {189 printf("Content-type: text/html\n\n");190 191 printf( "<html>\n");192 printf( " <head>\n");193 printf( " <title>Testing</title>\n");194 printf( " </head>\n");195 printf( " <body>\n");196 197 test_uni_read_pipe();198 test_uni_write_pipe();199 test_bi_read_write_pipe();200 201 printf( " </body>\n");202 printf( "</html>\n");203 204 return 0;205 }206 207 #endif208 -
main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.cpp
r22183 r22188 37 37 #endif 38 38 39 #include "text_t.h" 39 40 #include "os_process_windows.h" 40 41 41 //#include <stdio.h>42 43 osprocesswindows::osprocesswindows(char* cmdline)44 : osprocess(cmdline)45 {}46 42 47 43 osprocesswindows::osprocesswindows(OSProcessPipeMode mode, 48 char* prog_name, char* argv[] =NULL,44 char* prog_name, char* argv[], 49 45 char* envp[]) 50 46 : child_stdout_read_(NULL), child_stdin_write_(NULL), … … 91 87 92 88 si.dwFlags |= STARTF_USESTDHANDLES; 93 94 // any error messages in child process to to same place as parent process 89 90 91 // any error messages in the child process goes to same place as parent 95 92 // e.g. in the case of running as a CGI script, the Web server error log 96 93 si.hStdError = GetStdHandle(STD_ERROR_HANDLE); 97 94 98 // Output from the child process comes to the parent process, down the 99 // OUT pipe 100 si.hStdOutput = child_stdout_write; 101 102 // Input to the child process can be sent from the parent process, down the 103 // In pipe 104 si.hStdInput = child_stdin_read; 105 106 text_t cmd_line = ""; 95 if ((mode==uniRead) || (mode==biReadWrite)) { 96 // Output from the child process comes to the parent process, down the 97 // OUT pipe 98 si.hStdOutput = child_stdout_write; 99 } 100 else { 101 // uniWrite 102 // Output from the chlid process goes to the same place as parent 103 si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); 104 } 105 106 if ((mode==uniWrite) || (mode==biReadWrite)) { 107 // Input to the child process can be sent from the parent process, down the 108 // In pipe 109 si.hStdInput = child_stdin_read; 110 } 111 else { 112 // uniRead 113 114 // Input to the child process comes from same place as parent ?!? 115 si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); 116 } 117 118 text_t cmd_line = prog_name; 107 119 if (argv != NULL) { 108 int i= 0;120 int i=1; 109 121 while (argv[i] != NULL) { 110 if (i>0) { 111 cmd_line += " "; 112 } 113 cmd_line += "\"" + argv[i] + "\""; 122 cmd_line += " \""; 123 cmd_line += argv[i]; 124 cmd_line += "\""; 114 125 i++; 115 126 } … … 162 173 163 174 164 int osprocesswindows::write(c onst char* buffer, const int buffer_len)175 int osprocesswindows::write(char* buffer, const int buffer_len) 165 176 { 166 177 DWORD actual_write_len; … … 195 206 196 207 197 bool osprocess unix::close_write_pipe(OSProcessWarnStatus warn_status)208 bool osprocesswindows::close_write_pipe(OSProcessWarnStatus warn_status) 198 209 { 199 210 bool write_close_ok = true; 200 211 201 if (child_std out_read_ != NULL) {212 if (child_stdin_write_ != NULL) { 202 213 203 214 write_close_ok = CloseHandle(child_stdin_write_); … … 211 222 } 212 223 } 213 else if (warn ing_status == withWarning) {224 else if (warn_status == withWarning) { 214 225 cerr << "osprocesswindows::close_write_pipe(): Warning - Tried to close already closed pipe" << endl; 215 226 } … … 219 230 220 231 221 bool osprocess unix::close_read_pipe(OSProcessWarnStatus warn_status)232 bool osprocesswindows::close_read_pipe(OSProcessWarnStatus warn_status) 222 233 { 223 234 bool read_close_ok = true; -
main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.h
r22183 r22188 43 43 44 44 virtual int read(char* buffer, const int buffer_len); 45 virtual int write(c onst char* buffer, const int buffer_len);45 virtual int write(char* buffer, const int buffer_len); 46 46 47 47 virtual void wait(); 48 48 49 virtual bool close_write_pipe(OSProcessWarnStatus warn_status );50 virtual bool close_read_pipe(OSProcessWarnStatus warn_status );49 virtual bool close_write_pipe(OSProcessWarnStatus warn_status=withWarning); 50 virtual bool close_read_pipe(OSProcessWarnStatus warn_status=withWarning); 51 51 52 52 protected: -
main/trunk/greenstone2/runtime-src/src/recpt/win32.mak
r22090 r22188 186 186 .cpp.obj: 187 187 $(COMPILE) $< 188 189 OSPROCESS_SOURCES = \ 190 os_process.cpp \ 191 os_process_windows.cpp \ 192 193 OSPROCESS_OBJECTS = \ 194 os_process.obj \ 195 os_process_windows.obj \ 188 196 189 197 … … 218 226 librarymain.cpp \ 219 227 maincfg.cpp \ 228 $(OSPROCESS_SOURCES) \ 220 229 pageaction.cpp \ 221 230 pagedbrowserclass.cpp \ … … 265 274 librarymain.obj \ 266 275 maincfg.obj \ 276 $(OSPROCESS_OBJECTS) \ 267 277 pageaction.obj \ 268 278 pagedbrowserclass.obj \ … … 312 322 $(LINK) $(EXECUTABLE_OBJECTS) $(LIBS) 313 323 324 osprocess-test.cgi: $(OSPROCESS_OBJECTS) os_process_test.obj 325 $(LINK) $(OSPROCESS_OBJECTS) os_process_test.obj ..\..\..\common-src\src\lib\gsdllib.lib 326 314 327 !IF $(LOCAL_LIBRARY) 315 328 install:
Note:
See TracChangeset
for help on using the changeset viewer.