diff --git a/docs/latex/wx/process.tex b/docs/latex/wx/process.tex index 4f94f2b2a6..cd91098c18 100644 --- a/docs/latex/wx/process.tex +++ b/docs/latex/wx/process.tex @@ -260,6 +260,12 @@ A pointer to new wxProcess object or {\tt NULL} on error. \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} \func{void}{Redirect}{\void} diff --git a/include/wx/process.h b/include/wx/process.h index f707116868..a904f879ad 100644 --- a/include/wx/process.h +++ b/include/wx/process.h @@ -62,6 +62,9 @@ public: 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 virtual void OnTerminate(int pid, int status); @@ -103,8 +106,10 @@ public: protected: void Init(wxEvtHandler *parent, int id, int flags); + void SetPid(long pid) { m_pid = pid; } int m_id; + long m_pid; #if wxUSE_STREAMS // these streams are connected to stdout, stderr and stdin of the child diff --git a/samples/exec/exec.cpp b/samples/exec/exec.cpp index 13e9c0003d..3a30eff6de 100644 --- a/samples/exec/exec.cpp +++ b/samples/exec/exec.cpp @@ -774,6 +774,8 @@ void MyFrame::OnPOpen(wxCommandEvent& WXUNUSED(event)) return; } + wxLogVerbose(_T("PID of the new process: %ld"), process->GetPid()); + wxOutputStream *out = process->GetOutputStream(); if ( !out ) { diff --git a/src/common/process.cpp b/src/common/process.cpp index 9413b71d12..36764bf2f5 100644 --- a/src/common/process.cpp +++ b/src/common/process.cpp @@ -49,6 +49,7 @@ void wxProcess::Init(wxEvtHandler *parent, int id, int flags) SetNextHandler(parent); m_id = id; + m_pid = 0; m_redirect = (flags & wxPROCESS_REDIRECT) != 0; #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." )); wxProcess *process = new wxProcess(wxPROCESS_REDIRECT); - if ( !wxExecute(cmd, flags, process) ) + long pid = wxExecute(cmd, flags, process); + if( !pid ) { // couldn't launch the process delete process; return NULL; } + process->SetPid(pid); + return process; }