[22173] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * os_process.cpp --
|
---|
| 4 | * Copyright (C) 2010 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "os_process.h"
|
---|
| 27 |
|
---|
| 28 | osprocess::osprocess(char* cmdline, OSProcessPipeMode mode)
|
---|
| 29 | : mode_(mode)
|
---|
| 30 | {}
|
---|
| 31 |
|
---|
| 32 | osprocess::~osprocess()
|
---|
| 33 | {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[22177] | 36 | bool osprocess::close()
|
---|
[22173] | 37 | {
|
---|
[22177] | 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);
|
---|
[22173] | 44 | }
|
---|
| 45 |
|
---|
[22177] | 46 |
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | #if 1
|
---|
| 50 |
|
---|
| 51 | #include "os_process_windows.h"
|
---|
| 52 | #include "os_process_unix.h"
|
---|
| 53 | #include <iostream>
|
---|
| 54 | using namespace std;
|
---|
| 55 |
|
---|
| 56 | void test_uni_write_pipe()
|
---|
[22173] | 57 | {
|
---|
[22177] | 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
|
---|
[22173] | 69 |
|
---|
[22177] | 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 |
|
---|
[22173] | 90 | }
|
---|
| 91 |
|
---|
[22177] | 92 | int main()
|
---|
[22173] | 93 | {
|
---|
[22177] | 94 | printf("Content-type: text/html\n\n");
|
---|
[22173] | 95 |
|
---|
[22177] | 96 | printf( "<html>\n");
|
---|
| 97 | printf( " <head>\n");
|
---|
| 98 | printf( " <title>Testing</title>\n");
|
---|
| 99 | printf( " </head>\n");
|
---|
| 100 | printf( " <body>\n");
|
---|
[22173] | 101 |
|
---|
[22177] | 102 | test_uni_write_pipe();
|
---|
| 103 |
|
---|
| 104 | printf( " </body>\n");
|
---|
| 105 | printf( "</html>\n");
|
---|
| 106 |
|
---|
| 107 | return 0;
|
---|
[22173] | 108 | }
|
---|
| 109 |
|
---|
[22177] | 110 | #endif
|
---|
| 111 |
|
---|