+void MyFrame::OnExecWithRedirect(wxCommandEvent& WXUNUSED(event))
+{
+ wxString cmd = wxGetTextFromUser(_T("Enter the command: "),
+ DIALOG_TITLE,
+ m_cmdLast);
+
+ if ( !cmd )
+ return;
+
+ bool sync;
+ switch ( wxMessageBox(_T("Execute it synchronously?"),
+ _T("Exec question"),
+ wxYES_NO | wxCANCEL | wxICON_QUESTION, this) )
+ {
+ case wxYES:
+ sync = TRUE;
+ break;
+
+ case wxNO:
+ sync = FALSE;
+ break;
+
+ default:
+ return;
+ }
+
+ if ( sync )
+ {
+ wxArrayString output;
+ int code = wxExecute(cmd, output);
+ wxLogStatus(_T("command '%s' terminated with exit code %d."),
+ cmd.c_str(), code);
+
+ if ( code != -1 )
+ {
+ m_lbox->Append(wxString::Format(_T("--- Output of '%s' ---"),
+ cmd.c_str()));
+
+ size_t count = output.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ m_lbox->Append(output[n]);
+ }
+ }
+ }
+ else // async exec
+ {
+ MyPipedProcess *process = new MyPipedProcess(this, cmd);
+ if ( !wxExecute(cmd, FALSE /* async */, process) )
+ {
+ wxLogError(_T("Execution of '%s' failed."), cmd.c_str());
+
+ delete process;
+ }
+ else
+ {
+ m_running.Add(process);
+ }
+ }
+
+ m_cmdLast = cmd;
+}
+