wxProcess fixes (Detach() added), cleared/corrected wxExecute() documentation
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1709 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -946,11 +946,12 @@ arguments, terminated by NULL.
|
|||||||
If {\it sync} is FALSE (the default), flow of control immediately returns.
|
If {\it sync} is FALSE (the default), flow of control immediately returns.
|
||||||
If TRUE, the current application waits until the other program has terminated.
|
If TRUE, the current application waits until the other program has terminated.
|
||||||
|
|
||||||
If execution is asynchronous, the return value is the process id,
|
The return value is the process id, not the exit code of invoked program (for
|
||||||
otherwise it is a status value. A zero value indicates that the command could not
|
this you should use wxProcess). A zero value indicates that the command could
|
||||||
be executed.
|
not be executed.
|
||||||
|
|
||||||
If callback isn't NULL and if execution is asynchronous,
|
If callback isn't NULL and if execution is asynchronous (note that callback
|
||||||
|
parameter can not be non NULL for synchronous execution),
|
||||||
\helpref{wxProcess::OnTerminate}{wxprocessonterminate} will be called when
|
\helpref{wxProcess::OnTerminate}{wxprocessonterminate} will be called when
|
||||||
the process finishes.
|
the process finishes.
|
||||||
|
|
||||||
|
@@ -1,8 +1,18 @@
|
|||||||
\section{\class{wxProcess}}\label{wxprocess}
|
\section{\class{wxProcess}}\label{wxprocess}
|
||||||
|
|
||||||
This class contains a method which is invoked when a process finishes.
|
The objects of this class are used in conjonction with
|
||||||
It can raise a \helpref{wxProcessEvent}{wxprocessevent} if wxProcess::OnTerminate
|
\helpref{wxExecute}{wxexecute} function. When a wxProcess object is passed to
|
||||||
isn't overriden.
|
wxExecute(), its \helpref{OnTerminate()}{wxprocessonterminate} virtual method
|
||||||
|
is called when the process terminates. This allows the program to be
|
||||||
|
(asynchronously) notified about the process termination and also retrieve its
|
||||||
|
exit status which is unavailable from wxExecute() in the case of
|
||||||
|
asynchronous execution.
|
||||||
|
|
||||||
|
Please note that if the process termination notification is processed by the
|
||||||
|
parent, it is responsible for deleting the wxProcess object which sent it.
|
||||||
|
However, if it is not processed, the object will delete itself and so the
|
||||||
|
library users should only delete those objects whose notifications have been
|
||||||
|
processed (and call \helpref{Detach()}{wxprocessdetach} for others).
|
||||||
|
|
||||||
\wxheading{Derived from}
|
\wxheading{Derived from}
|
||||||
|
|
||||||
@@ -22,6 +32,10 @@ Constructs a process object. {\it id} is only used in the case you want to
|
|||||||
use wxWindows events. It identifies this object, or another window that will
|
use wxWindows events. It identifies this object, or another window that will
|
||||||
receive the event.
|
receive the event.
|
||||||
|
|
||||||
|
If the {\it parent} parameter is different from NULL, it will receive
|
||||||
|
a wxEVT\_END\_PROCESS notification event (you should insert EVT\_END\_PROCESS
|
||||||
|
macro in the event table of the parent to handle it) with the given {\it id}.
|
||||||
|
|
||||||
\wxheading{Parameters}
|
\wxheading{Parameters}
|
||||||
|
|
||||||
\docparam{parent}{The event handler parent.}
|
\docparam{parent}{The event handler parent.}
|
||||||
@@ -34,12 +48,28 @@ receive the event.
|
|||||||
|
|
||||||
Destroys the wxProcess object.
|
Destroys the wxProcess object.
|
||||||
|
|
||||||
|
\membersection{wxProcess::Detach}\label{wxprocessdetach}
|
||||||
|
|
||||||
|
\func{void}{Detach}{\void}
|
||||||
|
|
||||||
|
Normally, a wxProcess object is deleted by its parent when it receives the
|
||||||
|
notification about the process termination. However, it might happen that the
|
||||||
|
parent object is destroyed before the external process is terminated (e.g. a
|
||||||
|
window from which this external process was launched is closed by the user)
|
||||||
|
and in this case it {\bf should not delete} the wxProcess object, but
|
||||||
|
{\bf should call Detach()} instead. After the wxProcess object is detached
|
||||||
|
from its parent, no notification events will be sent to the parent and the
|
||||||
|
object will delete itself upon reception of the process termination
|
||||||
|
notification.
|
||||||
|
|
||||||
\membersection{wxProcess::OnTerminate}\label{wxprocessonterminate}
|
\membersection{wxProcess::OnTerminate}\label{wxprocessonterminate}
|
||||||
|
|
||||||
\constfunc{void}{OnTerminate}{\param{int}{ pid}}
|
\constfunc{void}{OnTerminate}{\param{int}{ pid}, \param{int}{ status}}
|
||||||
|
|
||||||
It is called when the process with the pid {\it pid} finishes.
|
It is called when the process with the pid {\it pid} finishes.
|
||||||
It raises a wxWindows event when it isn't overriden.
|
It raises a wxWindows event when it isn't overriden.
|
||||||
|
|
||||||
\docparam{pid}{The pid of the process which ends.}
|
\docparam{pid}{The pid of the process which has just terminated.}
|
||||||
|
|
||||||
|
\docparam{status}{The exit code of the process.}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
// Name: process.h
|
// Name: process.h
|
||||||
// Purpose: wxProcess class
|
// Purpose: wxProcess class
|
||||||
// Author: Guilhem Lavaux
|
// Author: Guilhem Lavaux
|
||||||
// Modified by:
|
// Modified by: Vadim Zeitlin to check error codes, added Detach() method
|
||||||
// Created: 24/06/98
|
// Created: 24/06/98
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) 1998 Guilhem Lavaux
|
// Copyright: (c) 1998 Guilhem Lavaux
|
||||||
@@ -55,6 +55,10 @@ public:
|
|||||||
|
|
||||||
virtual void OnTerminate(int pid, int status);
|
virtual void OnTerminate(int pid, int status);
|
||||||
|
|
||||||
|
// detach from the parent - should be called by the parent if it's deleted
|
||||||
|
// before the process it started terminates
|
||||||
|
void Detach();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_id;
|
int m_id;
|
||||||
};
|
};
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
// Name: process.cpp
|
// Name: process.cpp
|
||||||
// Purpose: Process termination classes
|
// Purpose: Process termination classes
|
||||||
// Author: Guilhem Lavaux
|
// Author: Guilhem Lavaux
|
||||||
// Modified by:
|
// Modified by: Vadim Zeitlin to check error codes, added Detach() method
|
||||||
// Created: 24/06/98
|
// Created: 24/06/98
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Guilhem Lavaux
|
// Copyright: (c) Guilhem Lavaux
|
||||||
@@ -41,5 +41,13 @@ void wxProcess::OnTerminate(int pid, int status)
|
|||||||
{
|
{
|
||||||
wxProcessEvent event(m_id, pid, status);
|
wxProcessEvent event(m_id, pid, status);
|
||||||
|
|
||||||
ProcessEvent(event);
|
if ( !ProcessEvent(event) )
|
||||||
|
delete this;
|
||||||
|
//else: the object which processed the event is responsible for deleting
|
||||||
|
// us!
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxProcess::Detach()
|
||||||
|
{
|
||||||
|
SetNextHandler(NULL);
|
||||||
}
|
}
|
||||||
|
@@ -320,6 +320,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
|
|||||||
{
|
{
|
||||||
// we're in child
|
// we're in child
|
||||||
close(end_proc_detect[0]); // close reading side
|
close(end_proc_detect[0]); // close reading side
|
||||||
|
|
||||||
// These three lines close the open file descriptors to
|
// These three lines close the open file descriptors to
|
||||||
// to avoid any input/output which might block the process
|
// to avoid any input/output which might block the process
|
||||||
// or irritate the user. If one wants proper IO for the sub-
|
// or irritate the user. If one wants proper IO for the sub-
|
||||||
@@ -328,6 +329,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
|
|||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
close(STDOUT_FILENO);
|
close(STDOUT_FILENO);
|
||||||
close(STDERR_FILENO);
|
close(STDERR_FILENO);
|
||||||
|
|
||||||
// some programs complain about sterr not being open, so
|
// some programs complain about sterr not being open, so
|
||||||
// redirect them:
|
// redirect them:
|
||||||
open("/dev/null", O_RDONLY); // stdin
|
open("/dev/null", O_RDONLY); // stdin
|
||||||
@@ -340,6 +342,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
|
|||||||
#else
|
#else
|
||||||
execvp (*argv, argv);
|
execvp (*argv, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// there is no return after successful exec()
|
// there is no return after successful exec()
|
||||||
wxLogSysError( "Can't execute '%s'", *argv);
|
wxLogSysError( "Can't execute '%s'", *argv);
|
||||||
|
|
||||||
|
@@ -320,6 +320,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
|
|||||||
{
|
{
|
||||||
// we're in child
|
// we're in child
|
||||||
close(end_proc_detect[0]); // close reading side
|
close(end_proc_detect[0]); // close reading side
|
||||||
|
|
||||||
// These three lines close the open file descriptors to
|
// These three lines close the open file descriptors to
|
||||||
// to avoid any input/output which might block the process
|
// to avoid any input/output which might block the process
|
||||||
// or irritate the user. If one wants proper IO for the sub-
|
// or irritate the user. If one wants proper IO for the sub-
|
||||||
@@ -328,6 +329,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
|
|||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
close(STDOUT_FILENO);
|
close(STDOUT_FILENO);
|
||||||
close(STDERR_FILENO);
|
close(STDERR_FILENO);
|
||||||
|
|
||||||
// some programs complain about sterr not being open, so
|
// some programs complain about sterr not being open, so
|
||||||
// redirect them:
|
// redirect them:
|
||||||
open("/dev/null", O_RDONLY); // stdin
|
open("/dev/null", O_RDONLY); // stdin
|
||||||
@@ -340,6 +342,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
|
|||||||
#else
|
#else
|
||||||
execvp (*argv, argv);
|
execvp (*argv, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// there is no return after successful exec()
|
// there is no return after successful exec()
|
||||||
wxLogSysError( "Can't execute '%s'", *argv);
|
wxLogSysError( "Can't execute '%s'", *argv);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user