]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 1586964 ] Getting the PID of the process executed by wxProcess::Open()
authorJulian Smart <julian@anthemion.co.uk>
Mon, 30 Oct 2006 09:03:18 +0000 (09:03 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Mon, 30 Oct 2006 09:03:18 +0000 (09:03 +0000)
by Lauri Nurmi

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42702 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/process.tex
include/wx/process.h
samples/exec/exec.cpp
src/common/process.cpp

index 4f94f2b2a67343113ae5f71d2bb4d91c042b52c8..cd91098c1899dbc05f98e28b859801912af58e7c 100644 (file)
@@ -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}
index f7071168680ebf16f5dec193b67cc6781e87f0d3..a904f879ad9aec3211ab284fd3a0a6270e3c225c 100644 (file)
@@ -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
index 13e9c0003d71da0ba1991046b92b76a83255ff39..3a30eff6de13b8e7305f9a48f9ade9fe9fa48214 100644 (file)
@@ -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 )
     {
index 9413b71d12b12fc69397dba240c2dfc2b39ec11c..36764bf2f5ff16a1921883a6ec8dc7897bbf436d 100644 (file)
@@ -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;
 }