All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pipechan.h
Go to the documentation of this file.
/*
* pipechan.h
*
* Sub-process with communications using pipe I/O channel class.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_PIPECHANNEL_H
#define PTLIB_PIPECHANNEL_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/channel.h>
class PChannel;
class PPipeChannel : public PChannel
{
PCLASSINFO(PPipeChannel, PChannel);
public:
enum OpenMode {
ReadOnly,
WriteOnly,
ReadWrite,
ReadWriteStd
};
PPipeChannel();
PPipeChannel(
const PString & subProgram,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
PPipeChannel(
const PString & subProgram,
const PStringArray & argumentList,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
PPipeChannel(
const PString & subProgram,
const PStringToString & environment,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
PPipeChannel(
const PString & subProgram,
const PStringArray & argumentList,
const PStringToString & environment,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
~PPipeChannel();
Comparison Compare(
const PObject & obj
) const;
virtual PString GetName() const;
virtual PBoolean Read(
void * buf,
PINDEX len
);
virtual PBoolean Write(
const void * buf,
PINDEX len
);
virtual PBoolean Close();
PBoolean Open(
const PString & subProgram,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
PBoolean Open(
const PString & subProgram,
const PStringArray & argumentList,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
PBoolean Open(
const PString & subProgram,
const PStringToString & environment,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
PBoolean Open(
const PString & subProgram,
const PStringArray & argumentList,
const PStringToString & environment,
OpenMode mode = ReadWrite,
PBoolean searchPath = true,
PBoolean stderrSeparate = false
);
const PFilePath & GetSubProgram() const;
PBoolean Execute();
PBoolean IsRunning() const;
int GetReturnCode() const;
int WaitForTermination();
int WaitForTermination(
const PTimeInterval & timeout
);
PBoolean Kill(
int signal = 9
);
PBoolean ReadStandardError(
PString & errors,
PBoolean wait = false
);
static PBoolean CanReadAndWrite();
protected:
// Member variables
PFilePath subProgName;
private:
PBoolean PlatformOpen(const PString & subProgram,
const PStringArray & arguments,
OpenMode mode,
PBoolean searchPath,
PBoolean stderrSeparate,
const PStringToString * environment);
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/pipechan.h"
#else
#include "unix/ptlib/pipechan.h"
#endif
};
#endif // PTLIB_PIPECHANNEL_H
// End Of File ///////////////////////////////////////////////////////////////
PTimeInterval
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PPipeChannel
Definition: pipechan.h:73
PPipeChannel::Open
PBoolean Open(const PString &subProgram, OpenMode mode=ReadWrite, PBoolean searchPath=true, PBoolean stderrSeparate=false)
Open a channel.
PPipeChannel::OpenMode
OpenMode
Channel mode for the pipe to the sub-process.
Definition: pipechan.h:81
PStringToString
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
PFilePath
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
PObject::Comparison
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PPipeChannel::CanReadAndWrite
static PBoolean CanReadAndWrite()
Determine if the platform can support simultaneous read and writes from the PPipeChannel (eg MSDOS re...
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PPipeChannel::ReadWrite
Pipe is bidirectional between current and sub-processes.
Definition: pipechan.h:87
PPipeChannel::GetName
virtual PString GetName() const
Get the name of the channel.
PBoolean
BOOL PBoolean
Definition: object.h:102
channel.h
PPipeChannel::subProgName
PFilePath subProgName
The fully qualified path name for the sub-program executable.
Definition: pipechan.h:392
PPipeChannel::Read
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PPipeChannel::ReadStandardError
PBoolean ReadStandardError(PString &errors, PBoolean wait=false)
Read all available data on the standard error stream of the sub-process.
PPipeChannel::Close
virtual PBoolean Close()
Close the channel.
PPipeChannel::WriteOnly
Pipe is only from the current process to the sub-process.
Definition: pipechan.h:85
PChannel
Abstract class defining I/O channel semantics.
Definition: channel.h:107
PString
The character string class.
Definition: pstring.h:108
PPipeChannel::Kill
PBoolean Kill(int signal=9)
This function will terminate the sub-program using the signal code specified.
PPipeChannel::Execute
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::~PPipeChannel
~PPipeChannel()
Close the pipe channel, killing the sub-process.
PPipeChannel::ReadWriteStd
Pipe is bidirectional between current and sub-processes but sub-processes stdout and stderr goes to c...
Definition: pipechan.h:91
PPipeChannel::ReadOnly
Pipe is only from the sub-process to the current process.
Definition: pipechan.h:83
PPipeChannel::Write
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PPipeChannel::Compare
Comparison Compare(const PObject &obj) const
Determine if the two objects refer to the same pipe channel.
PPipeChannel::WaitForTermination
int WaitForTermination()
This function will block and wait for the sub-program to terminate.
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PPipeChannel::PPipeChannel
PPipeChannel()
Create a new pipe channel.
PPipeChannel::IsRunning
PBoolean IsRunning() const
Determine if the program associated with the PPipeChannel is still executing.
PPipeChannel::GetReturnCode
int GetReturnCode() const
Get the return code from the most recent Close;.
PPipeChannel::GetSubProgram
const PFilePath & GetSubProgram() const
Get the full file path for the sub-programs executable file.