PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pipechan.h
Go to the documentation of this file.
1 /*
2  * pipechan.h
3  *
4  * Sub-process with communications using pipe I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  */
29 
30 #ifndef PTLIB_PIPECHANNEL_H
31 #define PTLIB_PIPECHANNEL_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 #if P_PIPECHAN
38 
39 #include <ptlib/channel.h>
40 
41 
68 class PChannel;
69 
70 
71 class PPipeChannel : public PChannel
72 {
73  PCLASSINFO(PPipeChannel, PChannel);
74 
75  public:
78  enum OpenMode {
81  ReadOnly,
83  WriteOnly,
85  ReadWrite,
89  ReadWriteStd
90  };
91 
94  PPipeChannel();
100  PPipeChannel(
101  const PString & subProgram,
102  OpenMode mode = ReadWrite,
103  PBoolean searchPath = true,
104  PBoolean stderrSeparate = false
105  );
111  PPipeChannel(
112  const PString & subProgram,
113  const PStringArray & argumentList,
114  OpenMode mode = ReadWrite,
115  PBoolean searchPath = true,
116  PBoolean stderrSeparate = false
117  );
123  PPipeChannel(
124  const PString & subProgram,
125  const PStringToString & environment,
126  OpenMode mode = ReadWrite,
127  PBoolean searchPath = true,
128  PBoolean stderrSeparate = false
129  );
135  PPipeChannel(
136  const PString & subProgram,
137  const PStringArray & argumentList,
138  const PStringToString & environment,
139  OpenMode mode = ReadWrite,
140  PBoolean searchPath = true,
141  PBoolean stderrSeparate = false
142  );
143 
145  ~PPipeChannel();
147 
157  Comparison Compare(
158  const PObject & obj
159  ) const;
161 
162 
170  virtual PString GetName() const;
171 
188  virtual PBoolean Read(
189  void * buf,
190  PINDEX len
191  );
192 
207  virtual PBoolean Write(
208  const void * buf,
209  PINDEX len
210  );
211 
220  virtual PBoolean Close();
222 
226  PBoolean Open(
227  const PString & subProgram,
228  OpenMode mode = ReadWrite,
229  PBoolean searchPath = true,
230  PBoolean stderrSeparate = false
231  );
233  PBoolean Open(
234  const PString & subProgram,
235  const PStringArray & argumentList,
236  OpenMode mode = ReadWrite,
237  PBoolean searchPath = true,
238  PBoolean stderrSeparate = false
239  );
241  PBoolean Open(
242  const PString & subProgram,
243  const PStringToString & environment,
244  OpenMode mode = ReadWrite,
245  PBoolean searchPath = true,
246  PBoolean stderrSeparate = false
247  );
285  PBoolean Open(
286  const PString & subProgram,
287  const PStringArray & argumentList,
288  const PStringToString & environment,
289  OpenMode mode = ReadWrite,
290  PBoolean searchPath = true,
291  PBoolean stderrSeparate = false
292  );
293 
299  const PFilePath & GetSubProgram() const;
300 
314  PBoolean Execute();
315 
324  PBoolean IsRunning() const;
325 
333  int GetReturnCode() const;
334 
340  int WaitForTermination();
341 
348  int WaitForTermination(
349  const PTimeInterval & timeout
350  );
351 
359  PBoolean Kill(
360  int signal = 9
361  );
362 
372  PBoolean ReadStandardError(
373  PString & errors,
374  PBoolean wait = false
375  );
376 
390  static int Run(
391  const PString & command,
392  PString & output,
393  bool includeStderr = true,
394  const PTimeInterval & timeout = PMaxTimeInterval
395  );
396 
403  static PBoolean CanReadAndWrite();
405 
406 
407  protected:
408  // Member variables
410  PFilePath subProgName;
411 
412 
413  private:
414  PBoolean PlatformOpen(const PString & subProgram,
415  const PStringArray & arguments,
416  OpenMode mode,
417  PBoolean searchPath,
418  PBoolean stderrSeparate,
419  const PStringToString * environment);
420 
421 
422 // Include platform dependent part of class
423 #ifdef _WIN32
424 #include "msos/ptlib/pipechan.h"
425 #else
426 #include "unix/ptlib/pipechan.h"
427 #endif
428 };
429 
430 
431 #endif // P_PIPECHAN
432 
433 #endif // PTLIB_PIPECHANNEL_H
434 
435 
436 // End Of File ///////////////////////////////////////////////////////////////
#define PMaxTimeInterval
Definition: timeint.h:31
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
virtual PBoolean Close()
Close the channel, shutting down the link to the data source.
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:3151
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
virtual PString GetName() const =0
Get the platform and I/O channel type name of the channel.
This is an array collection class of PString objects.
Definition: pstring.h:2365
virtual Comparison Compare(const PObject &obj) const
Get the relative rank of the two strings.
Abstract class defining I/O channel semantics.
Definition: channel.h:103
bool PBoolean
Definition: object.h:174
The character string class.
Definition: pstring.h:108
Ultimate parent class for all objects in the class library.
Definition: object.h:2204