+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
+ {
+ wxLogError(_T("Execution of '%s' failed."), cmd.c_str());
+
+ delete process;
+ }
+
+ m_cmdLast = cmd;
+}
+
+void MyFrame::OnFileExec(wxCommandEvent& event)
+{
+ static wxString s_filename;
+
+ wxString filename = wxLoadFileSelector(_T("file"), _T(""), s_filename);
+ if ( !filename )
+ return;
+
+ s_filename = filename;
+
+ wxString ext = filename.AfterFirst(_T('.'));
+ wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
+ if ( !ft )
+ {
+ wxLogError(_T("Impossible to determine the file type for extension '%s'"),
+ ext.c_str());
+ return;
+ }
+
+ wxString cmd;
+ bool ok = ft->GetOpenCommand(&cmd,
+ wxFileType::MessageParameters(filename, _T("")));
+ delete ft;
+ if ( !ok )
+ {
+ wxLogError(_T("Impossible to find out how to open files of extension '%s'"),
+ ext.c_str());
+ return;
+ }
+
+ DoAsyncExec(cmd);
+}
+