1998-07-01 13:26:46 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: process.h
|
|
|
|
// Purpose: wxProcess class
|
|
|
|
// Author: Guilhem Lavaux
|
1999-02-17 12:56:59 -05:00
|
|
|
// Modified by: Vadim Zeitlin to check error codes, added Detach() method
|
1998-07-01 13:26:46 -04:00
|
|
|
// Created: 24/06/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Guilhem Lavaux
|
1999-02-17 12:56:59 -05:00
|
|
|
// Licence: wxWindows license
|
1998-07-01 13:26:46 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_PROCESSH__
|
|
|
|
#define _WX_PROCESSH__
|
1998-07-01 13:26:46 -04:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-02-07 16:26:54 -05:00
|
|
|
#pragma interface "process.h"
|
1998-07-01 13:26:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/event.h"
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
#if wxUSE_STREAMS
|
2000-02-27 05:44:49 -05:00
|
|
|
#include "wx/stream.h"
|
2000-07-15 15:51:35 -04:00
|
|
|
#endif
|
1998-07-01 13:26:46 -04:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
// Process Event handling
|
|
|
|
class WXDLLEXPORT wxProcessEvent : public wxEvent
|
1998-07-01 13:26:46 -04:00
|
|
|
{
|
1999-02-07 16:26:54 -05:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxProcessEvent)
|
1998-07-01 13:26:46 -04:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
public:
|
|
|
|
wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0) : wxEvent(id)
|
|
|
|
{
|
|
|
|
m_eventType = wxEVT_END_PROCESS;
|
|
|
|
m_pid = pid;
|
|
|
|
m_exitcode = exitcode;
|
|
|
|
}
|
1998-07-01 13:26:46 -04:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
// accessors
|
|
|
|
// PID of process which terminated
|
|
|
|
int GetPid() { return m_pid; }
|
1998-07-01 13:26:46 -04:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
// the exit code
|
|
|
|
int GetExitCode() { return m_exitcode; }
|
1998-07-01 13:26:46 -04:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
public:
|
|
|
|
int m_pid, m_exitcode;
|
|
|
|
};
|
1998-07-01 13:26:46 -04:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
// A wxProcess object should be passed to wxExecute - than its OnTerminate()
|
|
|
|
// function will be called when the process terminates.
|
|
|
|
class WXDLLEXPORT wxProcess : public wxEvtHandler
|
1998-07-01 13:26:46 -04:00
|
|
|
{
|
1999-02-07 16:26:54 -05:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxProcess)
|
|
|
|
|
|
|
|
public:
|
2000-03-02 14:06:13 -05:00
|
|
|
wxProcess(wxEvtHandler *parent = (wxEvtHandler *) NULL, int id = -1)
|
|
|
|
{ Init(parent, id, FALSE); }
|
|
|
|
wxProcess(wxEvtHandler *parent, bool redirect)
|
|
|
|
{ Init(parent, -1, redirect); }
|
1998-07-01 13:26:46 -04:00
|
|
|
|
2000-03-02 14:06:13 -05:00
|
|
|
virtual ~wxProcess();
|
|
|
|
|
|
|
|
// may be overridden to be notified about process termination
|
1999-02-07 16:26:54 -05:00
|
|
|
virtual void OnTerminate(int pid, int status);
|
1998-07-01 13:26:46 -04:00
|
|
|
|
2000-03-02 14:06:13 -05:00
|
|
|
// call this before passing the object to wxExecute() to redirect the
|
|
|
|
// launched process stdin/stdout, then use GetInputStream() and
|
|
|
|
// GetOutputStream() to get access to them
|
|
|
|
void Redirect() { m_redirect = TRUE; }
|
|
|
|
bool IsRedirected() const { return m_redirect; }
|
|
|
|
|
1999-02-17 12:56:59 -05:00
|
|
|
// detach from the parent - should be called by the parent if it's deleted
|
|
|
|
// before the process it started terminates
|
|
|
|
void Detach();
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
#if wxUSE_STREAMS
|
2000-02-27 05:44:49 -05:00
|
|
|
// Pipe handling
|
2000-03-02 14:06:13 -05:00
|
|
|
wxInputStream *GetInputStream() const { return m_inputStream; }
|
2000-07-15 15:51:35 -04:00
|
|
|
wxInputStream *GetErrorStream() const { return m_errorStream; }
|
2000-03-02 14:06:13 -05:00
|
|
|
wxOutputStream *GetOutputStream() const { return m_outputStream; }
|
2000-02-27 05:44:49 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
// close the output stream indicating that nothing more will be written
|
|
|
|
void CloseOutput() { delete m_outputStream; m_outputStream = NULL; }
|
|
|
|
|
2000-03-02 14:06:13 -05:00
|
|
|
// implementation only (for wxExecute)
|
2000-07-15 15:51:35 -04:00
|
|
|
void SetPipeStreams(wxInputStream *inStream,
|
|
|
|
wxOutputStream *outStream,
|
|
|
|
wxInputStream *errStream);
|
|
|
|
#endif // wxUSE_STREAMS
|
2000-02-27 05:44:49 -05:00
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
protected:
|
2000-03-02 14:06:13 -05:00
|
|
|
void Init(wxEvtHandler *parent, int id, bool redirect);
|
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
int m_id;
|
2000-03-02 14:06:13 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
#if wxUSE_STREAMS
|
|
|
|
wxInputStream *m_inputStream,
|
|
|
|
*m_errorStream;
|
2000-03-02 14:06:13 -05:00
|
|
|
wxOutputStream *m_outputStream;
|
2000-07-15 15:51:35 -04:00
|
|
|
#endif // wxUSE_STREAMS
|
2000-03-02 14:06:13 -05:00
|
|
|
|
|
|
|
bool m_redirect;
|
1998-07-01 13:26:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&);
|
|
|
|
|
1999-02-07 16:26:54 -05:00
|
|
|
#define EVT_END_PROCESS(id, func) { wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL},
|
1998-07-01 13:26:46 -04:00
|
|
|
|
|
|
|
#endif
|
1998-08-14 20:23:28 -04:00
|
|
|
// _WX_PROCESSH__
|