Changeset 22174


Ignore:
Timestamp:
05/26/10 00:01:29 (11 years ago)
Author:
davidb
Message:

Syntax errors corrected

Location:
main/trunk/greenstone2/runtime-src/src/recpt
Files:
2 edited

Legend:

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

    r22173 r22174  
    4444#define WRITE_PIPE_INDEX 1
    4545
     46#define FD_STDIN 0
     47#define FD_STDOUT 1
     48#define FD_STDERR 2
    4649
    4750osprocessunix::osprocessunix(char* cmdline)
     
    5053
    5154osprocessunix::osprocessunix(char* cmdline, OSProcessPipeMode mode)
    52   : child_stdout_read_(NULL), child_stdin_write_(NULL),
     55  : child_stdout_read_(-1), child_stdin_write_(-1),
    5356    osprocess(cmdline,mode)
    5457{
     
    8992    // Sort out input pipe
    9093    //   child has no buisness accessing write end of input pipe => close
    91     close(child_stdin_write_);   
     94    ::close(child_stdin_write_);   
    9295
    9396    if ((mode == uniWrite) || (mode == biReadWrite)) {
     
    99102      // in the child reading any input from the parent)
    100103      // => child input remains coming from stdin
    101       close(child_stdin_read);
     104      ::close(child_stdin_read);
    102105    }
    103106
    104107    // Sort out output pipe
    105108    //   child has no buisness accessing read end of output pipe => close
    106     close(child_stdout_read_);
     109    ::close(child_stdout_read_);
    107110    if ((mode == uniRead) || (mode == biReadWrite)) {
    108111      //   wire up child's stdout write so it is send down the pipe to the parent
     
    113116      // in any output produced by the child process)
    114117      // => child output remains going to stdout
    115       close(child_stdout_write);
    116     }
    117 
     118      ::close(child_stdout_write);
     119    }
     120
     121    /*
    118122    // execve ...
    119123    int rv = CreateProcess(NULL,    // no application name
     
    130134      fprintf(stderr,"os_process_windows(): Error creating process");
    131135    }
     136    */
     137
    132138   
    133139  }
     
    137143    // Sort out input pipe
    138144    //    parent has no buisness accessing read end of input pipe => close
    139     close(child_stdin_read);
     145    ::close(child_stdin_read);
    140146
    141147    // Sort out output pipe
    142148    //    parent has no buisness accessing write end of output pipe => close
    143     close(child_stdout_write);
     149    ::close(child_stdout_write);
    144150
    145151
     
    147153    {
    148154      case uniRead:
    149     close(child_stdin_write_);
     155    ::close(child_stdin_write_);
    150156    break;
    151157      case uniWrite:
    152     close(child_stdout_read_);
     158    ::close(child_stdout_read_);
    153159    break;
    154160      case biReadWrite:
     
    157163    break;
    158164      case noPipe:
    159     close(child_stdin_write_);
    160     close(child_stdout_read_);
     165    ::close(child_stdin_write_);
     166    ::close(child_stdout_read_);
    161167    break;
    162168    }
     
    178184{
    179185
    180   int actual_write_len = write(child_stdin_write_, buffer, buffer_len);
    181  
    182   if (data_written<0) {
     186  int actual_write_len = ::write(child_stdin_write_, buffer, buffer_len);
     187 
     188  if (actual_write_len<0) {
    183189    cerr << "osproessunix::write() Error: failed to write data" << endl;
    184190  }
     
    189195int osprocessunix::read(char* buffer, const int buffer_len)
    190196{
    191   int actual_read_len = read(child_stdout_read_, buffer, buffer_len);
     197  int actual_read_len = ::read(child_stdout_read_, buffer, buffer_len);
    192198
    193199  if (actual_read_len<0) {
     
    201207 
    202208bool osprocessunix::close()
    203 {}
     209{
     210  return true;
     211}
    204212
    205213bool osprocessunix::close(OSProcessPipeMode mode)
    206 {}
    207 
    208 
    209 int main()  {
    210  int  pipe_fd[2];
    211  pipe(pipe_fd);
    212 
    213  if (fork() == 0)  {                     /* create child process          */
    214   char *av[3] = { "ls", "-c1", 0};       /* parameters for command        */
    215   close(pipe_fd[0]);                     /* close read end of pipe        */ 
    216   close(1);                              /* close standard output         */
    217   dup(pipe_fd[1]);                       /* attach write end of pipe      */
    218                                          /* stdout is lowest available fd */
    219   execve("/bin/ls", av, 0);              /* run the ls code               */
    220  }
    221  else  {                                 /* in the parent process         */
    222   int files;
    223   char ch;
    224   close(pipe_fd[1]);                     /* close write end of pipe       */
    225   files = 0;                             /* counter for number of files   */
    226        
    227   while ( 0 != read(pipe_fd[0], &ch, 1) )/* read from pipe until eof      */
    228    if (ch == '\n')                       /* each newline represents a file*/
    229     ++files;       
    230    cout<< "There are " << files << " files\n";
    231   }
    232 }
     214{
     215  return true;
     216}
     217
     218
    233219
    234220#endif
  • main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.h

    r22173 r22174  
    3838   
    3939 public:
    40   osprocessunix(const char* cmd);
    41   osprocessunix(const char* cmd, const OSProcessPipeMode mode);
    42   virutal ~osprocessunix();
     40  osprocessunix(char* cmd);
     41  osprocessunix(char* cmd, OSProcessPipeMode mode);
     42  virtual ~osprocessunix();
    4343 
    44   virtual eop();                  // end of pipe
    45   virtual eop(OSProcessPipeMode); // end of pipe, for named pipe
     44  /*
     45  virtual bool eop();                  // end of pipe
     46  virtual bool eop(OSProcessPipeMode); // end of pipe, for designated pipe
     47  */
    4648
    4749  virtual int read(char* buffer, const int buffer_len);
    48   virtual bool write(char* buffer, const int buffer_len);
     50  virtual int write(char* buffer, const int buffer_len);
    4951 
    5052  virtual bool close();
     
    5254
    5355 protected:
    54   File* read_fd_;
    55   File* write_fd_;
     56  int child_stdin_write_;
     57  int child_stdout_read_;
    5658};
    5759
Note: See TracChangeset for help on using the changeset viewer.