csProcess OnTerminate doesn't work

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

csProcess OnTerminate doesn't work

Post by kea_ » Tue Jan 13, 2009 2:36 pm

Hello together,

I like to execute vbScripts and .exe file. If one of this process is killed from anybody I would like to know for sending a message or something like that.
I can start the process but if I kill the process the OnTerminate event don't work.

This is the source:

Code: Select all

--- main.cpp ---

#include "csExecutable.h"
#include <wx/string.h>
#include <wx/app.h>
#include <iostream>

using namespace std;

int main(int argc, const char* argv[])
{
    wxInitializer initializer;

    wxString sExecutable = "cscript d:/my_projects/cpp/bbExec/App1.vbs";
    csExecutable *exec = new csExecutable(sExecutable);
    exec->Run(60);
    delete exec;

    return 0;
}

--- csExecutable.h ---
#ifndef CS_EXECUTABLE_H
#define CS_EXECUTABLE_H

#include <wx/string.h>
#include <wx/process.h>
#include <wx/txtstrm.h>
#include <wx/datetime.h>
#include <wx/thread.h>
#include <iostream>

using namespace std;


class csExecutable : public wxProcess
{
	public:
		// FUNCTIONS
		csExecutable(wxString sExecutable);
		~csExecutable();
		void Run(long lMaxSeconds);

		// PARAMETERS

	protected:
		// FUNCTION
		// PARAMETER

	private:
		// FUNCTIONS
		// PARAMETERS
		wxString m_sExecutable;

		// EVENTS
		void OnTerminate(int pid, int status);
};

#endif // CS_EXECUTABLE_H


--- csExecutable.cpp ---

#include "csExecutable.h"

csExecutable::csExecutable(wxString sExecutable)
            : wxProcess(wxPROCESS_REDIRECT){
    m_sExecutable = sExecutable;
    cout << "csExecutable.Constructor: " << m_sExecutable << endl;
}


csExecutable::~csExecutable(){}


void csExecutable::Run(long lMaxSeconds){
    long pid = wxExecute(m_sExecutable, wxEXEC_ASYNC, this);
    this->Redirect();

    if(this){
        wxInputStream *is = this->GetInputStream();
        wxTextInputStream tStream(*is);
        while(!is->Eof()){
            cout << tStream.ReadLine() << " " << wxDateTime::Now().FormatISODate() << endl;
            Kill(pid, wxSIGKILL, wxKILL_CHILDREN);
        }

        //cout << "End of process!" << endl;
    }

}


// ** E V E N T S  ***
void csExecutable::OnTerminate(int pid, int status){
    cout << "<<<<<<<<< OnTerminate >>>>>>>>>>>>>" << endl;
}
Has anybody a helping hand for me.
Thanks kea_

Post Reply