+ 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, errors;
+ int code = wxExecute(cmd, output, errors);
+ wxLogStatus(_T("command '%s' terminated with exit code %d."),
+ cmd.c_str(), code);
+
+ if ( code != -1 )
+ {
+ ShowOutput(cmd, output, _T("Output"));
+ ShowOutput(cmd, errors, _T("Errors"));
+ }
+ }
+ 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;
+}
+
+void MyFrame::OnExecWithPipe(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !m_cmdLast )
+ m_cmdLast = _T("tr [a-z] [A-Z]");
+
+ wxString cmd = wxGetTextFromUser(_T("Enter the command: "),
+ DIALOG_TITLE,
+ m_cmdLast);
+
+ if ( !cmd )
+ return;
+
+ wxString input = wxGetTextFromUser(_T("Enter the string to send to it: "),
+ DIALOG_TITLE);
+ if ( !input )
+ return;
+
+ // always execute the filter asynchronously
+ MyPipedProcess2 *process = new MyPipedProcess2(this, cmd, input);
+ int pid = wxExecute(cmd, FALSE /* async */, process);
+ if ( pid )
+ {
+ wxLogStatus(_T("Process %ld (%s) launched."), pid, cmd.c_str());
+
+ m_running.Add(process);
+ }
+ else