1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: exec sample demonstrates wxExecute and related functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "exec.cpp"
22 #pragma interface "exec.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers
41 #include "wx/msgdlg.h"
42 #include "wx/textdlg.h"
43 #include "wx/filedlg.h"
44 #include "wx/choicdlg.h"
46 #include "wx/button.h"
47 #include "wx/textctrl.h"
48 #include "wx/listbox.h"
53 #include "wx/txtstrm.h"
55 #include "wx/process.h"
57 #include "wx/mimetype.h"
63 // ----------------------------------------------------------------------------
64 // the usual application and main frame classes
65 // ----------------------------------------------------------------------------
67 // Define a new application type, each program should derive a class from wxApp
68 class MyApp
: public wxApp
71 // override base class virtuals
72 // ----------------------------
74 // this one is called on application startup and is a good place for the app
75 // initialization (doing it here and not in the ctor allows to have an error
76 // return: if OnInit() returns false, the application terminates)
77 virtual bool OnInit();
80 // Define an array of process pointers used by MyFrame
82 WX_DEFINE_ARRAY(MyPipedProcess
*, MyProcessesArray
);
84 // Define a new frame type: this is going to be our main frame
85 class MyFrame
: public wxFrame
89 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
91 // event handlers (these functions should _not_ be virtual)
92 void OnQuit(wxCommandEvent
& event
);
94 void OnKill(wxCommandEvent
& event
);
96 void OnClear(wxCommandEvent
& event
);
98 void OnSyncExec(wxCommandEvent
& event
);
99 void OnAsyncExec(wxCommandEvent
& event
);
100 void OnShell(wxCommandEvent
& event
);
101 void OnExecWithRedirect(wxCommandEvent
& event
);
102 void OnExecWithPipe(wxCommandEvent
& event
);
104 void OnPOpen(wxCommandEvent
& event
);
106 void OnFileExec(wxCommandEvent
& event
);
108 void OnAbout(wxCommandEvent
& event
);
110 // polling output of async processes
111 void OnIdle(wxIdleEvent
& event
);
113 // for MyPipedProcess
114 void OnProcessTerminated(MyPipedProcess
*process
);
115 wxListBox
*GetLogListBox() const { return m_lbox
; }
118 void ShowOutput(const wxString
& cmd
,
119 const wxArrayString
& output
,
120 const wxString
& title
);
122 void DoAsyncExec(const wxString
& cmd
);
124 // the PID of the last process we launched asynchronously
127 // last command we executed
131 void OnDDEExec(wxCommandEvent
& event
);
132 void OnDDERequest(wxCommandEvent
& event
);
136 // last params of a DDE transaction
140 #endif // __WINDOWS__
144 MyProcessesArray m_running
;
146 // any class wishing to process wxWindows events must use this macro
147 DECLARE_EVENT_TABLE()
150 // ----------------------------------------------------------------------------
151 // MyPipeFrame: allows the user to communicate with the child process
152 // ----------------------------------------------------------------------------
154 class MyPipeFrame
: public wxFrame
157 MyPipeFrame(wxFrame
*parent
,
162 void OnTextEnter(wxCommandEvent
& event
) { DoSend(); }
163 void OnBtnSend(wxCommandEvent
& event
) { DoSend(); }
164 void OnBtnGet(wxCommandEvent
& event
) { DoGet(); }
166 void OnClose(wxCloseEvent
& event
);
168 void OnProcessTerm(wxProcessEvent
& event
);
172 m_out
.WriteString(m_textIn
->GetValue() + '\n');
181 wxProcess
*m_process
;
183 wxTextInputStream m_in
;
184 wxTextOutputStream m_out
;
186 wxTextCtrl
*m_textIn
,
189 DECLARE_EVENT_TABLE()
192 // ----------------------------------------------------------------------------
193 // wxProcess-derived classes
194 // ----------------------------------------------------------------------------
196 // This is the handler for process termination events
197 class MyProcess
: public wxProcess
200 MyProcess(MyFrame
*parent
, const wxString
& cmd
)
201 : wxProcess(parent
), m_cmd(cmd
)
206 // instead of overriding this virtual function we might as well process the
207 // event from it in the frame class - this might be more convenient in some
209 virtual void OnTerminate(int pid
, int status
);
216 // A specialization of MyProcess for redirecting the output
217 class MyPipedProcess
: public MyProcess
220 MyPipedProcess(MyFrame
*parent
, const wxString
& cmd
)
221 : MyProcess(parent
, cmd
)
226 virtual void OnTerminate(int pid
, int status
);
228 virtual bool HasInput();
231 // A version of MyPipedProcess which also sends input to the stdin of the
233 class MyPipedProcess2
: public MyPipedProcess
236 MyPipedProcess2(MyFrame
*parent
, const wxString
& cmd
, const wxString
& input
)
237 : MyPipedProcess(parent
, cmd
), m_input(input
)
241 virtual bool HasInput();
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 // IDs for the controls and the menu commands
270 Exec_Btn_Send
= 1000,
274 static const wxChar
*DIALOG_TITLE
= _T("Exec sample");
276 // ----------------------------------------------------------------------------
277 // event tables and other macros for wxWindows
278 // ----------------------------------------------------------------------------
280 // the event tables connect the wxWindows events with the functions (event
281 // handlers) which process them. It can be also done at run-time, but for the
282 // simple menu events like this the static method is much simpler.
283 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
284 EVT_MENU(Exec_Quit
, MyFrame
::OnQuit
)
285 EVT_MENU(Exec_Kill
, MyFrame
::OnKill
)
286 EVT_MENU(Exec_ClearLog
, MyFrame
::OnClear
)
288 EVT_MENU(Exec_SyncExec
, MyFrame
::OnSyncExec
)
289 EVT_MENU(Exec_AsyncExec
, MyFrame
::OnAsyncExec
)
290 EVT_MENU(Exec_Shell
, MyFrame
::OnShell
)
291 EVT_MENU(Exec_Redirect
, MyFrame
::OnExecWithRedirect
)
292 EVT_MENU(Exec_Pipe
, MyFrame
::OnExecWithPipe
)
294 EVT_MENU(Exec_POpen
, MyFrame
::OnPOpen
)
296 EVT_MENU(Exec_OpenFile
, MyFrame
::OnFileExec
)
299 EVT_MENU(Exec_DDEExec
, MyFrame
::OnDDEExec
)
300 EVT_MENU(Exec_DDERequest
, MyFrame
::OnDDERequest
)
301 #endif // __WINDOWS__
303 EVT_MENU(Exec_About
, MyFrame
::OnAbout
)
305 EVT_IDLE(MyFrame
::OnIdle
)
308 BEGIN_EVENT_TABLE(MyPipeFrame
, wxFrame
)
309 EVT_BUTTON(Exec_Btn_Send
, MyPipeFrame
::OnBtnSend
)
310 EVT_BUTTON(Exec_Btn_Get
, MyPipeFrame
::OnBtnGet
)
312 EVT_TEXT_ENTER(-1, MyPipeFrame
::OnTextEnter
)
314 EVT_CLOSE(MyPipeFrame
::OnClose
)
316 EVT_END_PROCESS(-1, MyPipeFrame
::OnProcessTerm
)
319 // Create a new application object: this macro will allow wxWindows to create
320 // the application object during program execution (it's better than using a
321 // static object for many reasons) and also declares the accessor function
322 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
326 // ============================================================================
328 // ============================================================================
330 // ----------------------------------------------------------------------------
331 // the application class
332 // ----------------------------------------------------------------------------
334 // `Main program' equivalent: the program execution "starts" here
337 // Create the main application window
338 MyFrame
*frame
= new MyFrame(_T("Exec wxWindows sample"),
339 wxDefaultPosition
, wxSize(500, 140));
341 // Show it and tell the application that it's our main window
345 // success: wxApp::OnRun() will be called which will enter the main message
346 // loop and the application will run. If we returned FALSE here, the
347 // application would exit immediately.
351 // ----------------------------------------------------------------------------
353 // ----------------------------------------------------------------------------
356 MyFrame
::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
357 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
362 // we need this in order to allow the about menu relocation, since ABOUT is
363 // not the default id of the about menu
364 wxApp
::s_macAboutMenuItemId
= Exec_About
;
368 wxMenu
*menuFile
= new wxMenu(_T(""), wxMENU_TEAROFF
);
369 menuFile
->Append(Exec_Kill
, _T("&Kill process...\tCtrl-K"),
370 _T("Kill a process by PID"));
371 menuFile
->AppendSeparator();
372 menuFile
->Append(Exec_ClearLog
, _T("&Clear log\tCtrl-C"),
373 _T("Clear the log window"));
374 menuFile
->AppendSeparator();
375 menuFile
->Append(Exec_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
377 wxMenu
*execMenu
= new wxMenu
;
378 execMenu
->Append(Exec_SyncExec
, _T("Sync &execution...\tCtrl-E"),
379 _T("Launch a program and return when it terminates"));
380 execMenu
->Append(Exec_AsyncExec
, _T("&Async execution...\tCtrl-A"),
381 _T("Launch a program and return immediately"));
382 execMenu
->Append(Exec_Shell
, _T("Execute &shell command...\tCtrl-S"),
383 _T("Launch a shell and execute a command in it"));
384 execMenu
->AppendSeparator();
385 execMenu
->Append(Exec_Redirect
, _T("Capture command &output...\tCtrl-O"),
386 _T("Launch a program and capture its output"));
387 execMenu
->Append(Exec_Pipe
, _T("&Pipe through command..."),
388 _T("Pipe a string through a filter"));
389 execMenu
->Append(Exec_POpen
, _T("&Open a pipe to a command...\tCtrl-P"),
390 _T("Open a pipe to and from another program"));
392 execMenu
->AppendSeparator();
393 execMenu
->Append(Exec_OpenFile
, _T("Open &file...\tCtrl-F"),
394 _T("Launch the command to open this kind of files"));
396 execMenu
->AppendSeparator();
397 execMenu
->Append(Exec_DDEExec
, _T("Execute command via &DDE...\tCtrl-D"));
398 execMenu
->Append(Exec_DDERequest
, _T("Send DDE &request...\tCtrl-R"));
401 wxMenu
*helpMenu
= new wxMenu(_T(""), wxMENU_TEAROFF
);
402 helpMenu
->Append(Exec_About
, _T("&About...\tF1"), _T("Show about dialog"));
404 // now append the freshly created menu to the menu bar...
405 wxMenuBar
*menuBar
= new wxMenuBar();
406 menuBar
->Append(menuFile
, _T("&File"));
407 menuBar
->Append(execMenu
, _T("&Exec"));
408 menuBar
->Append(helpMenu
, _T("&Help"));
410 // ... and attach this menu bar to the frame
413 // create the listbox in which we will show misc messages as they come
414 m_lbox
= new wxListBox(this, -1);
415 wxFont
font(12, wxFONTFAMILY_TELETYPE
, wxFONTSTYLE_NORMAL
,
416 wxFONTWEIGHT_NORMAL
);
418 m_lbox
->SetFont(font
);
421 // create a status bar just for fun (by default with 1 pane only)
423 SetStatusText(_T("Welcome to wxWindows exec sample!"));
424 #endif // wxUSE_STATUSBAR
427 // ----------------------------------------------------------------------------
428 // event handlers: file and help menu
429 // ----------------------------------------------------------------------------
431 void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
))
433 // TRUE is to force the frame to close
437 void MyFrame
::OnClear(wxCommandEvent
& WXUNUSED(event
))
442 void MyFrame
::OnAbout(wxCommandEvent
& WXUNUSED(event
))
444 wxMessageBox(_T("Exec wxWindows Sample\n© 2000-2001 Vadim Zeitlin"),
445 _T("About Exec"), wxOK
| wxICON_INFORMATION
, this);
448 void MyFrame
::OnKill(wxCommandEvent
& WXUNUSED(event
))
450 long pid
= wxGetNumberFromUser(_T("Please specify the process to kill"),
454 // we need the full unsigned int range
463 static const wxString signalNames
[] =
465 _T("Just test (SIGNONE)"),
466 _T("Hangup (SIGHUP)"),
467 _T("Interrupt (SIGINT)"),
468 _T("Quit (SIGQUIT)"),
469 _T("Illegal instruction (SIGILL)"),
470 _T("Trap (SIGTRAP)"),
471 _T("Abort (SIGABRT)"),
472 _T("Emulated trap (SIGEMT)"),
473 _T("FP exception (SIGFPE)"),
474 _T("Kill (SIGKILL)"),
476 _T("Segment violation (SIGSEGV)"),
477 _T("System (SIGSYS)"),
478 _T("Broken pipe (SIGPIPE)"),
479 _T("Alarm (SIGALRM)"),
480 _T("Terminate (SIGTERM)"),
483 int sig
= wxGetSingleChoiceIndex(_T("How to kill the process?"),
485 WXSIZEOF(signalNames
), signalNames
,
490 wxFAIL_MSG( _T("unexpected return value") );
518 if ( wxProcess
::Exists(pid
) )
519 wxLogStatus(_T("Process %ld is running."), pid
);
521 wxLogStatus(_T("No process with pid = %ld."), pid
);
525 wxKillError rc
= wxProcess
::Kill(pid
, (wxSignal
)sig
);
526 if ( rc
== wxKILL_OK
)
528 wxLogStatus(_T("Process %ld killed with signal %d."), pid
, sig
);
532 static const wxChar
*errorText
[] =
535 _T("signal not supported"),
536 _T("permission denied"),
537 _T("no such process"),
538 _T("unspecified error"),
541 wxLogStatus(_T("Failed to kill process %ld with signal %d: %s"),
542 pid
, sig
, errorText
[rc
]);
547 // ----------------------------------------------------------------------------
548 // event handlers: exec menu
549 // ----------------------------------------------------------------------------
551 void MyFrame
::DoAsyncExec(const wxString
& cmd
)
553 wxProcess
*process
= new MyProcess(this, cmd
);
554 m_pidLast
= wxExecute(cmd
, wxEXEC_ASYNC
, process
);
557 wxLogError( _T("Execution of '%s' failed."), cmd
.c_str() );
563 wxLogStatus( _T("Process %ld (%s) launched."),
564 m_pidLast
, cmd
.c_str() );
570 void MyFrame
::OnSyncExec(wxCommandEvent
& WXUNUSED(event
))
572 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
579 wxLogStatus( _T("'%s' is running please wait..."), cmd
.c_str() );
581 int code
= wxExecute(cmd
, wxEXEC_SYNC
);
583 wxLogStatus(_T("Process '%s' terminated with exit code %d."),
589 void MyFrame
::OnAsyncExec(wxCommandEvent
& WXUNUSED(event
))
591 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
601 void MyFrame
::OnShell(wxCommandEvent
& WXUNUSED(event
))
603 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
610 int code
= wxShell(cmd
);
611 wxLogStatus(_T("Shell command '%s' terminated with exit code %d."),
616 void MyFrame
::OnExecWithRedirect(wxCommandEvent
& WXUNUSED(event
))
618 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
626 switch ( wxMessageBox(_T("Execute it synchronously?"),
628 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this) )
644 wxArrayString output
, errors
;
645 int code
= wxExecute(cmd
, output
, errors
);
646 wxLogStatus(_T("command '%s' terminated with exit code %d."),
651 ShowOutput(cmd
, output
, _T("Output"));
652 ShowOutput(cmd
, errors
, _T("Errors"));
657 MyPipedProcess
*process
= new MyPipedProcess(this, cmd
);
658 if ( !wxExecute(cmd
, wxEXEC_ASYNC
, process
) )
660 wxLogError(_T("Execution of '%s' failed."), cmd
.c_str());
666 m_running
.Add(process
);
673 void MyFrame
::OnExecWithPipe(wxCommandEvent
& WXUNUSED(event
))
676 m_cmdLast
= _T("tr [a-z] [A-Z]");
678 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
685 wxString input
= wxGetTextFromUser(_T("Enter the string to send to it: "),
690 // always execute the filter asynchronously
691 MyPipedProcess2
*process
= new MyPipedProcess2(this, cmd
, input
);
692 long pid
= wxExecute(cmd
, wxEXEC_ASYNC
, process
);
695 wxLogStatus( _T("Process %ld (%s) launched."), pid
, cmd
.c_str() );
697 m_running
.Add(process
);
701 wxLogError(_T("Execution of '%s' failed."), cmd
.c_str());
709 void MyFrame
::OnPOpen(wxCommandEvent
& event
)
711 wxString cmd
= wxGetTextFromUser(_T("Enter the command to launch: "),
717 wxProcess
*process
= wxProcess
::Open(cmd
);
720 wxLogError(_T("Failed to launch the command."));
724 wxOutputStream
*out
= process
->GetOutputStream();
727 wxLogError(_T("Failed to connect to child stdin"));
731 wxInputStream
*in
= process
->GetInputStream();
734 wxLogError(_T("Failed to connect to child stdout"));
738 new MyPipeFrame(this, cmd
, process
);
741 void MyFrame
::OnFileExec(wxCommandEvent
& event
)
743 static wxString s_filename
;
745 wxString filename
= wxLoadFileSelector(_T(""), _T(""), s_filename
);
749 s_filename
= filename
;
751 wxString ext
= filename
.AfterFirst(_T('.'));
752 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
755 wxLogError(_T("Impossible to determine the file type for extension '%s'"),
761 bool ok
= ft
->GetOpenCommand(&cmd
,
762 wxFileType
::MessageParameters(filename
, _T("")));
766 wxLogError(_T("Impossible to find out how to open files of extension '%s'"),
774 // ----------------------------------------------------------------------------
776 // ----------------------------------------------------------------------------
780 bool MyFrame
::GetDDEServer()
782 wxString server
= wxGetTextFromUser(_T("Server to connect to:"),
783 DIALOG_TITLE
, m_server
);
789 wxString topic
= wxGetTextFromUser(_T("DDE topic:"), DIALOG_TITLE
, m_topic
);
795 wxString cmd
= wxGetTextFromUser(_T("DDE command:"), DIALOG_TITLE
, m_cmdDde
);
804 void MyFrame
::OnDDEExec(wxCommandEvent
& WXUNUSED(event
))
806 if ( !GetDDEServer() )
810 wxConnectionBase
*conn
= client
.MakeConnection("", m_server
, m_topic
);
813 wxLogError(_T("Failed to connect to the DDE server '%s'."),
818 if ( !conn
->Execute(m_cmdDde
) )
820 wxLogError(_T("Failed to execute command '%s' via DDE."),
825 wxLogStatus(_T("Successfully executed DDE command"));
830 void MyFrame
::OnDDERequest(wxCommandEvent
& WXUNUSED(event
))
832 if ( !GetDDEServer() )
836 wxConnectionBase
*conn
= client
.MakeConnection("", m_server
, m_topic
);
839 wxLogError(_T("Failed to connect to the DDE server '%s'."),
844 if ( !conn
->Request(m_cmdDde
) )
846 wxLogError(_T("Failed to send request '%s' via DDE."),
851 wxLogStatus(_T("Successfully sent DDE request."));
856 #endif // __WINDOWS__
858 // ----------------------------------------------------------------------------
860 // ----------------------------------------------------------------------------
863 void MyFrame
::OnIdle(wxIdleEvent
& event
)
865 size_t count
= m_running
.GetCount();
866 for ( size_t n
= 0; n
< count
; n
++ )
868 if ( m_running
[n
]->HasInput() )
875 void MyFrame
::OnProcessTerminated(MyPipedProcess
*process
)
877 m_running
.Remove(process
);
881 void MyFrame
::ShowOutput(const wxString
& cmd
,
882 const wxArrayString
& output
,
883 const wxString
& title
)
885 size_t count
= output
.GetCount();
889 m_lbox
->Append(wxString
::Format(_T("--- %s of '%s' ---"),
890 title
.c_str(), cmd
.c_str()));
892 for ( size_t n
= 0; n
< count
; n
++ )
894 m_lbox
->Append(output
[n
]);
897 m_lbox
->Append(wxString
::Format(_T("--- End of %s ---"),
898 title
.Lower().c_str()));
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
905 void MyProcess
::OnTerminate(int pid
, int status
)
907 wxLogStatus(m_parent
, _T("Process %u ('%s') terminated with exit code %d."),
908 pid
, m_cmd
.c_str(), status
);
910 // we're not needed any more
914 // ----------------------------------------------------------------------------
916 // ----------------------------------------------------------------------------
918 bool MyPipedProcess
::HasInput()
920 bool hasInput
= FALSE
;
922 wxInputStream
& is
= *GetInputStream();
925 wxTextInputStream
tis(is
);
927 // this assumes that the output is always line buffered
929 msg
<< m_cmd
<< _T(" (stdout): ") << tis
.ReadLine();
931 m_parent
->GetLogListBox()->Append(msg
);
936 wxInputStream
& es
= *GetErrorStream();
939 wxTextInputStream
tis(es
);
941 // this assumes that the output is always line buffered
943 msg
<< m_cmd
<< _T(" (stderr): ") << tis
.ReadLine();
945 m_parent
->GetLogListBox()->Append(msg
);
953 void MyPipedProcess
::OnTerminate(int pid
, int status
)
955 // show the rest of the output
959 m_parent
->OnProcessTerminated(this);
961 MyProcess
::OnTerminate(pid
, status
);
964 // ----------------------------------------------------------------------------
966 // ----------------------------------------------------------------------------
968 bool MyPipedProcess2
::HasInput()
972 wxTextOutputStream
os(*GetOutputStream());
973 os
.WriteString(m_input
);
978 // call us once again - may be we'll have output
982 return MyPipedProcess
::HasInput();
985 // ============================================================================
986 // MyPipeFrame implementation
987 // ============================================================================
989 MyPipeFrame
::MyPipeFrame(wxFrame
*parent
,
992 : wxFrame(parent
, -1, cmd
),
994 // in a real program we'd check that the streams are !NULL here
995 m_in(*process
->GetInputStream()),
996 m_out(*process
->GetOutputStream())
998 m_process
->SetNextHandler(this);
1000 wxPanel
*panel
= new wxPanel(this, -1);
1002 m_textIn
= new wxTextCtrl(panel
, -1, _T(""),
1003 wxDefaultPosition
, wxDefaultSize
,
1004 wxTE_PROCESS_ENTER
);
1005 m_textOut
= new wxTextCtrl(panel
, -1, _T(""));
1006 m_textOut
->SetEditable(FALSE
);
1008 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1009 sizerTop
->Add(m_textIn
, 0, wxGROW
| wxALL
, 5);
1011 wxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
1012 sizerBtns
->Add(new wxButton(panel
, Exec_Btn_Send
, _T("&Send")), 0,
1014 sizerBtns
->Add(new wxButton(panel
, Exec_Btn_Get
, _T("&Get")), 0,
1017 sizerTop
->Add(sizerBtns
, 0, wxCENTRE
| wxALL
, 5);
1018 sizerTop
->Add(m_textOut
, 0, wxGROW
| wxALL
, 5);
1020 panel
->SetSizer(sizerTop
);
1021 sizerTop
->Fit(this);
1026 void MyPipeFrame
::DoGet()
1028 // we don't have any way to be notified when any input appears on the
1029 // stream so we have to poll it :-(
1031 // NB: this really must be done because otherwise the other program might
1032 // not have enough time to receive or process our data and we'd read
1034 while ( !m_process
->IsInputAvailable() && m_process
->IsInputOpened() )
1037 m_textOut
->SetValue(m_in
.ReadLine());
1040 void MyPipeFrame
::OnClose(wxCloseEvent
& event
)
1044 // we're not interested in getting the process termination notification
1045 // if we are closing it ourselves
1046 wxProcess
*process
= m_process
;
1048 process
->SetNextHandler(NULL
);
1050 process
->CloseOutput();
1056 void MyPipeFrame
::OnProcessTerm(wxProcessEvent
& event
)
1061 wxLogWarning(_T("The other process has terminated, closing"));