1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <wx/string.h>
#include <wx/process.h>
#include <wx/cmdline.h>
#include <wx/crt.h>
const wxCmdLineEntryDesc gCmdLineDesc[] = {
{ wxCMD_LINE_OPTION, "n", "name", "Executable to launch", wxCMD_LINE_VAL_STRING },
{ wxCMD_LINE_NONE }
};
bool Process (wxCmdLineParser& parser);
void PrintUsage();
int main(int argc, char **argv)
{
wxCmdLineParser parser(argc, argv);
parser.SetDesc (gCmdLineDesc);
parser.SetSwitchChars (wxT("-"));
Process( parser );
return 0;
}
bool Process(wxCmdLineParser& parser)
{
parser.Parse();
// long process_id (wxNOT_FOUND);
wxString exe_name(wxEmptyString);
//We got a command to close eTrigger
// parser.Found(wxT("pid"), &process_id);
parser.Found(wxT("name"), &exe_name);
if ( /*process_id == wxNOT_FOUND || */exe_name.IsEmpty() ) {
PrintUsage();
return false;
}
// Kill the process
// if (wxProcess::Exists(process_id)) {
//
// //Okay, then let's close parent.exe
// int killError = wxProcess::Kill(process_id, wxSIGTERM);
// if (killError) {
// if (killError == wxKILL_BAD_SIGNAL) {
// wxPrintf(wxT("wxProcess::Kill Error: no such signal\n"));
// return true;
// }
// if (killError == wxKILL_ACCESS_DENIED) {
// wxPrintf(wxT("wxProcess::Kill Error: permission denied\n"));
// return true;
// }
// if (killError == wxKILL_NO_PROCESS) {
// wxPrintf(wxT("wxProcess::Kill Error: no such process\n"));
// return true;
// }
// if (killError == wxKILL_ERROR) {
// wxPrintf(wxT("An Error occurred attempting to close parent.exe, the helper will now attempt to forcefully close %s\n"), exe_name.c_str());
// int killError2 = wxProcess::Kill(process_id, wxSIGKILL);
// if (killError2) {
// wxPrintf(wxT("The Helper could not close %s\n"), exe_name.c_str());
// return true;
// }
// }
// }
// } else {
// wxPrintf(wxT("Error: process %d does not exist\n"), process_id);
// }
// Now let's open the parent
wxProcess proc;
wxSleep( 3 );
proc.Open(wxString::Format(wxT("%s"), exe_name.c_str()), wxEXEC_ASYNC | wxEXEC_NOHIDE);
proc.Detach();
}
void PrintUsage() {
wxPrintf(wxT("codelite_restarter --pid=<number> --name=<string>\n"));
wxPrintf(wxT("--pid,-p Process ID\n"));
wxPrintf(wxT("--name,-n Executable to launch\n"));
}
|