PTLib  Version 2.10.11
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  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_PIPECHANNEL_H
35 #define PTLIB_PIPECHANNEL_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib/channel.h>
42 
43 
70 class PChannel;
71 
72 
73 class PPipeChannel : public PChannel
74 {
75  PCLASSINFO(PPipeChannel, PChannel);
76 
77  public:
80  enum OpenMode {
92  };
93 
96  PPipeChannel();
102  PPipeChannel(
103  const PString & subProgram,
104  OpenMode mode = ReadWrite,
105  PBoolean searchPath = true,
106  PBoolean stderrSeparate = false
107  );
113  PPipeChannel(
114  const PString & subProgram,
115  const PStringArray & argumentList,
116  OpenMode mode = ReadWrite,
117  PBoolean searchPath = true,
118  PBoolean stderrSeparate = false
119  );
125  PPipeChannel(
126  const PString & subProgram,
127  const PStringToString & environment,
128  OpenMode mode = ReadWrite,
129  PBoolean searchPath = true,
130  PBoolean stderrSeparate = false
131  );
137  PPipeChannel(
138  const PString & subProgram,
139  const PStringArray & argumentList,
140  const PStringToString & environment,
141  OpenMode mode = ReadWrite,
142  PBoolean searchPath = true,
143  PBoolean stderrSeparate = false
144  );
145 
147  ~PPipeChannel();
149 
160  const PObject & obj
161  ) const;
163 
164 
172  virtual PString GetName() const;
173 
190  virtual PBoolean Read(
191  void * buf,
192  PINDEX len
193  );
194 
209  virtual PBoolean Write(
210  const void * buf,
211  PINDEX len
212  );
213 
222  virtual PBoolean Close();
224 
228  PBoolean Open(
229  const PString & subProgram,
230  OpenMode mode = ReadWrite,
231  PBoolean searchPath = true,
232  PBoolean stderrSeparate = false
233  );
235  PBoolean Open(
236  const PString & subProgram,
237  const PStringArray & argumentList,
238  OpenMode mode = ReadWrite,
239  PBoolean searchPath = true,
240  PBoolean stderrSeparate = false
241  );
243  PBoolean Open(
244  const PString & subProgram,
245  const PStringToString & environment,
246  OpenMode mode = ReadWrite,
247  PBoolean searchPath = true,
248  PBoolean stderrSeparate = false
249  );
287  PBoolean Open(
288  const PString & subProgram,
289  const PStringArray & argumentList,
290  const PStringToString & environment,
291  OpenMode mode = ReadWrite,
292  PBoolean searchPath = true,
293  PBoolean stderrSeparate = false
294  );
295 
301  const PFilePath & GetSubProgram() const;
302 
316  PBoolean Execute();
317 
326  PBoolean IsRunning() const;
327 
335  int GetReturnCode() const;
336 
342  int WaitForTermination();
343 
350  int WaitForTermination(
351  const PTimeInterval & timeout
352  );
353 
361  PBoolean Kill(
362  int signal = 9
363  );
364 
375  PString & errors,
376  PBoolean wait = false
377  );
378 
385  static PBoolean CanReadAndWrite();
387 
388 
389  protected:
390  // Member variables
393 
394 
395  private:
396  PBoolean PlatformOpen(const PString & subProgram,
397  const PStringArray & arguments,
398  OpenMode mode,
399  PBoolean searchPath,
400  PBoolean stderrSeparate,
401  const PStringToString * environment);
402 
403 
404 // Include platform dependent part of class
405 #ifdef _WIN32
406 #include "msos/ptlib/pipechan.h"
407 #else
408 #include "unix/ptlib/pipechan.h"
409 #endif
410 };
411 
412 
413 #endif // PTLIB_PIPECHANNEL_H
414 
415 
416 // End Of File ///////////////////////////////////////////////////////////////
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
Definition: pipechan.h:73
PBoolean Open(const PString &subProgram, OpenMode mode=ReadWrite, PBoolean searchPath=true, PBoolean stderrSeparate=false)
Open a channel.
OpenMode
Channel mode for the pipe to the sub-process.
Definition: pipechan.h:81
const PFilePath & GetSubProgram() const
Get the full file path for the sub-programs executable file.
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PBoolean IsRunning() const
Determine if the program associated with the PPipeChannel is still executing.
static PBoolean CanReadAndWrite()
Determine if the platform can support simultaneous read and writes from the PPipeChannel (eg MSDOS re...
Comparison Compare(const PObject &obj) const
Determine if the two objects refer to the same pipe channel.
This is an array collection class of PString objects.
Definition: pstring.h:2024
Pipe is bidirectional between current and sub-processes.
Definition: pipechan.h:87
BOOL PBoolean
Definition: object.h:102
PFilePath subProgName
The fully qualified path name for the sub-program executable.
Definition: pipechan.h:392
virtual PString GetName() const
Get the name of the channel.
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PBoolean ReadStandardError(PString &errors, PBoolean wait=false)
Read all available data on the standard error stream of the sub-process.
virtual PBoolean Close()
Close the channel.
Pipe is only from the current process to the sub-process.
Definition: pipechan.h:85
Abstract class defining I/O channel semantics.
Definition: channel.h:107
The character string class.
Definition: pstring.h:108
PBoolean Kill(int signal=9)
This function will terminate the sub-program using the signal code specified.
PBoolean Execute()
Start execution of sub-program for platforms that do not support multi-processing, this will actually run the sub-program passing all data written to the PPipeChannel.
~PPipeChannel()
Close the pipe channel, killing the sub-process.
Pipe is bidirectional between current and sub-processes but sub-processes stdout and stderr goes to c...
Definition: pipechan.h:91
Pipe is only from the sub-process to the current process.
Definition: pipechan.h:83
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
int WaitForTermination()
This function will block and wait for the sub-program to terminate.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PPipeChannel()
Create a new pipe channel.
int GetReturnCode() const
Get the return code from the most recent Close;.