Applied patch [ 1586964 ] Getting the PID of the process executed by wxProcess::Open()
by Lauri Nurmi git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42702 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4a4bf7eefb
commit
a387938f80
@ -260,6 +260,12 @@ A pointer to new wxProcess object or {\tt NULL} on error.
|
|||||||
|
|
||||||
\helpref{wxExecute}{wxexecute}
|
\helpref{wxExecute}{wxexecute}
|
||||||
|
|
||||||
|
\membersection{wxProcess::GetPid}\label{wxprocessgetpid}
|
||||||
|
|
||||||
|
\constfunc{long}{GetPid}{\void}
|
||||||
|
|
||||||
|
Returns the process ID of the process launched by \helpref{Open}{wxprocessopen}.
|
||||||
|
|
||||||
\membersection{wxProcess::Redirect}\label{wxprocessredirect}
|
\membersection{wxProcess::Redirect}\label{wxprocessredirect}
|
||||||
|
|
||||||
\func{void}{Redirect}{\void}
|
\func{void}{Redirect}{\void}
|
||||||
|
@ -62,6 +62,9 @@ public:
|
|||||||
|
|
||||||
virtual ~wxProcess();
|
virtual ~wxProcess();
|
||||||
|
|
||||||
|
// get the process ID of the process executed by Open()
|
||||||
|
long GetPid() const { return m_pid; }
|
||||||
|
|
||||||
// may be overridden to be notified about process termination
|
// may be overridden to be notified about process termination
|
||||||
virtual void OnTerminate(int pid, int status);
|
virtual void OnTerminate(int pid, int status);
|
||||||
|
|
||||||
@ -103,8 +106,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init(wxEvtHandler *parent, int id, int flags);
|
void Init(wxEvtHandler *parent, int id, int flags);
|
||||||
|
void SetPid(long pid) { m_pid = pid; }
|
||||||
|
|
||||||
int m_id;
|
int m_id;
|
||||||
|
long m_pid;
|
||||||
|
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
// these streams are connected to stdout, stderr and stdin of the child
|
// these streams are connected to stdout, stderr and stdin of the child
|
||||||
|
@ -774,6 +774,8 @@ void MyFrame::OnPOpen(wxCommandEvent& WXUNUSED(event))
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxLogVerbose(_T("PID of the new process: %ld"), process->GetPid());
|
||||||
|
|
||||||
wxOutputStream *out = process->GetOutputStream();
|
wxOutputStream *out = process->GetOutputStream();
|
||||||
if ( !out )
|
if ( !out )
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,7 @@ void wxProcess::Init(wxEvtHandler *parent, int id, int flags)
|
|||||||
SetNextHandler(parent);
|
SetNextHandler(parent);
|
||||||
|
|
||||||
m_id = id;
|
m_id = id;
|
||||||
|
m_pid = 0;
|
||||||
m_redirect = (flags & wxPROCESS_REDIRECT) != 0;
|
m_redirect = (flags & wxPROCESS_REDIRECT) != 0;
|
||||||
|
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
@ -63,13 +64,16 @@ wxProcess *wxProcess::Open(const wxString& cmd, int flags)
|
|||||||
{
|
{
|
||||||
wxASSERT_MSG( !(flags & wxEXEC_SYNC), wxT("wxEXEC_SYNC should not be used." ));
|
wxASSERT_MSG( !(flags & wxEXEC_SYNC), wxT("wxEXEC_SYNC should not be used." ));
|
||||||
wxProcess *process = new wxProcess(wxPROCESS_REDIRECT);
|
wxProcess *process = new wxProcess(wxPROCESS_REDIRECT);
|
||||||
if ( !wxExecute(cmd, flags, process) )
|
long pid = wxExecute(cmd, flags, process);
|
||||||
|
if( !pid )
|
||||||
{
|
{
|
||||||
// couldn't launch the process
|
// couldn't launch the process
|
||||||
delete process;
|
delete process;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process->SetPid(pid);
|
||||||
|
|
||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user