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
44 #include "wx/msgdlg.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/choicdlg.h"
49 #include "wx/button.h"
50 #include "wx/textctrl.h"
51 #include "wx/listbox.h"
56 #include "wx/txtstrm.h"
58 #include "wx/process.h"
60 #include "wx/mimetype.h"
66 // ----------------------------------------------------------------------------
67 // the usual application and main frame classes
68 // ----------------------------------------------------------------------------
70 // Define a new application type, each program should derive a class from wxApp
71 class MyApp
: public wxApp
74 // override base class virtuals
75 // ----------------------------
77 // this one is called on application startup and is a good place for the app
78 // initialization (doing it here and not in the ctor allows to have an error
79 // return: if OnInit() returns false, the application terminates)
80 virtual bool OnInit();
83 // Define an array of process pointers used by MyFrame
85 WX_DEFINE_ARRAY(MyPipedProcess
*, MyProcessesArray
);
87 // Define a new frame type: this is going to be our main frame
88 class MyFrame
: public wxFrame
92 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
94 // event handlers (these functions should _not_ be virtual)
95 void OnQuit(wxCommandEvent
& event
);
97 void OnKill(wxCommandEvent
& event
);
99 void OnClear(wxCommandEvent
& event
);
101 void OnSyncExec(wxCommandEvent
& event
);
102 void OnAsyncExec(wxCommandEvent
& event
);
103 void OnShell(wxCommandEvent
& event
);
104 void OnExecWithRedirect(wxCommandEvent
& event
);
105 void OnExecWithPipe(wxCommandEvent
& event
);
107 void OnPOpen(wxCommandEvent
& event
);
109 void OnFileExec(wxCommandEvent
& event
);
111 void OnAbout(wxCommandEvent
& event
);
113 // polling output of async processes
114 void OnTimer(wxTimerEvent
& event
);
115 void OnIdle(wxIdleEvent
& event
);
117 // for MyPipedProcess
118 void OnProcessTerminated(MyPipedProcess
*process
);
119 wxListBox
*GetLogListBox() const { return m_lbox
; }
122 void ShowOutput(const wxString
& cmd
,
123 const wxArrayString
& output
,
124 const wxString
& title
);
126 void DoAsyncExec(const wxString
& cmd
);
128 void AddAsyncProcess(MyPipedProcess
*process
)
130 if ( m_running
.IsEmpty() )
132 // we want to start getting the timer events to ensure that a
133 // steady stream of idle events comes in -- otherwise we
134 // wouldn't be able to poll the child process input
135 m_timerIdleWakeUp
.Start(100);
137 //else: the timer is already running
139 m_running
.Add(process
);
142 void RemoveAsyncProcess(MyPipedProcess
*process
)
144 m_running
.Remove(process
);
146 if ( m_running
.IsEmpty() )
148 // we don't need to get idle events all the time any more
149 m_timerIdleWakeUp
.Stop();
153 // the PID of the last process we launched asynchronously
156 // last command we executed
160 void OnDDEExec(wxCommandEvent
& event
);
161 void OnDDERequest(wxCommandEvent
& event
);
165 // last params of a DDE transaction
169 #endif // __WINDOWS__
173 MyProcessesArray m_running
;
175 // the idle event wake up timer
176 wxTimer m_timerIdleWakeUp
;
178 // any class wishing to process wxWindows events must use this macro
179 DECLARE_EVENT_TABLE()
182 // ----------------------------------------------------------------------------
183 // MyPipeFrame: allows the user to communicate with the child process
184 // ----------------------------------------------------------------------------
186 class MyPipeFrame
: public wxFrame
189 MyPipeFrame(wxFrame
*parent
,
194 void OnTextEnter(wxCommandEvent
& event
) { DoSend(); }
195 void OnBtnSend(wxCommandEvent
& event
) { DoSend(); }
196 void OnBtnGet(wxCommandEvent
& event
) { DoGet(); }
198 void OnClose(wxCloseEvent
& event
);
200 void OnProcessTerm(wxProcessEvent
& event
);
204 m_out
.WriteString(m_textIn
->GetValue() + '\n');
213 wxProcess
*m_process
;
215 wxTextInputStream m_in
;
216 wxTextOutputStream m_out
;
218 wxTextCtrl
*m_textIn
,
221 DECLARE_EVENT_TABLE()
224 // ----------------------------------------------------------------------------
225 // wxProcess-derived classes
226 // ----------------------------------------------------------------------------
228 // This is the handler for process termination events
229 class MyProcess
: public wxProcess
232 MyProcess(MyFrame
*parent
, const wxString
& cmd
)
233 : wxProcess(parent
), m_cmd(cmd
)
238 // instead of overriding this virtual function we might as well process the
239 // event from it in the frame class - this might be more convenient in some
241 virtual void OnTerminate(int pid
, int status
);
248 // A specialization of MyProcess for redirecting the output
249 class MyPipedProcess
: public MyProcess
252 MyPipedProcess(MyFrame
*parent
, const wxString
& cmd
)
253 : MyProcess(parent
, cmd
)
258 virtual void OnTerminate(int pid
, int status
);
260 virtual bool HasInput();
263 // A version of MyPipedProcess which also sends input to the stdin of the
265 class MyPipedProcess2
: public MyPipedProcess
268 MyPipedProcess2(MyFrame
*parent
, const wxString
& cmd
, const wxString
& input
)
269 : MyPipedProcess(parent
, cmd
), m_input(input
)
273 virtual bool HasInput();
279 // ----------------------------------------------------------------------------
281 // ----------------------------------------------------------------------------
283 // IDs for the controls and the menu commands
302 Exec_Btn_Send
= 1000,
306 static const wxChar
*DIALOG_TITLE
= _T("Exec sample");
308 // ----------------------------------------------------------------------------
309 // event tables and other macros for wxWindows
310 // ----------------------------------------------------------------------------
312 // the event tables connect the wxWindows events with the functions (event
313 // handlers) which process them. It can be also done at run-time, but for the
314 // simple menu events like this the static method is much simpler.
315 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
316 EVT_MENU(Exec_Quit
, MyFrame::OnQuit
)
317 EVT_MENU(Exec_Kill
, MyFrame::OnKill
)
318 EVT_MENU(Exec_ClearLog
, MyFrame::OnClear
)
320 EVT_MENU(Exec_SyncExec
, MyFrame::OnSyncExec
)
321 EVT_MENU(Exec_AsyncExec
, MyFrame::OnAsyncExec
)
322 EVT_MENU(Exec_Shell
, MyFrame::OnShell
)
323 EVT_MENU(Exec_Redirect
, MyFrame::OnExecWithRedirect
)
324 EVT_MENU(Exec_Pipe
, MyFrame::OnExecWithPipe
)
326 EVT_MENU(Exec_POpen
, MyFrame::OnPOpen
)
328 EVT_MENU(Exec_OpenFile
, MyFrame::OnFileExec
)
331 EVT_MENU(Exec_DDEExec
, MyFrame::OnDDEExec
)
332 EVT_MENU(Exec_DDERequest
, MyFrame::OnDDERequest
)
333 #endif // __WINDOWS__
335 EVT_MENU(Exec_About
, MyFrame::OnAbout
)
337 EVT_IDLE(MyFrame::OnIdle
)
339 EVT_TIMER(-1, MyFrame::OnTimer
)
342 BEGIN_EVENT_TABLE(MyPipeFrame
, wxFrame
)
343 EVT_BUTTON(Exec_Btn_Send
, MyPipeFrame::OnBtnSend
)
344 EVT_BUTTON(Exec_Btn_Get
, MyPipeFrame::OnBtnGet
)
346 EVT_TEXT_ENTER(-1, MyPipeFrame::OnTextEnter
)
348 EVT_CLOSE(MyPipeFrame::OnClose
)
350 EVT_END_PROCESS(-1, MyPipeFrame::OnProcessTerm
)
353 // Create a new application object: this macro will allow wxWindows to create
354 // the application object during program execution (it's better than using a
355 // static object for many reasons) and also declares the accessor function
356 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
360 // ============================================================================
362 // ============================================================================
364 // ----------------------------------------------------------------------------
365 // the application class
366 // ----------------------------------------------------------------------------
368 // `Main program' equivalent: the program execution "starts" here
371 // Create the main application window
372 MyFrame
*frame
= new MyFrame(_T("Exec wxWindows sample"),
373 wxDefaultPosition
, wxSize(500, 140));
375 // Show it and tell the application that it's our main window
379 // success: wxApp::OnRun() will be called which will enter the main message
380 // loop and the application will run. If we returned FALSE here, the
381 // application would exit immediately.
385 // ----------------------------------------------------------------------------
387 // ----------------------------------------------------------------------------
390 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
391 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
),
392 m_timerIdleWakeUp(this)
397 // we need this in order to allow the about menu relocation, since ABOUT is
398 // not the default id of the about menu
399 wxApp::s_macAboutMenuItemId
= Exec_About
;
403 wxMenu
*menuFile
= new wxMenu(_T(""), wxMENU_TEAROFF
);
404 menuFile
->Append(Exec_Kill
, _T("&Kill process...\tCtrl-K"),
405 _T("Kill a process by PID"));
406 menuFile
->AppendSeparator();
407 menuFile
->Append(Exec_ClearLog
, _T("&Clear log\tCtrl-C"),
408 _T("Clear the log window"));
409 menuFile
->AppendSeparator();
410 menuFile
->Append(Exec_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
412 wxMenu
*execMenu
= new wxMenu
;
413 execMenu
->Append(Exec_SyncExec
, _T("Sync &execution...\tCtrl-E"),
414 _T("Launch a program and return when it terminates"));
415 execMenu
->Append(Exec_AsyncExec
, _T("&Async execution...\tCtrl-A"),
416 _T("Launch a program and return immediately"));
417 execMenu
->Append(Exec_Shell
, _T("Execute &shell command...\tCtrl-S"),
418 _T("Launch a shell and execute a command in it"));
419 execMenu
->AppendSeparator();
420 execMenu
->Append(Exec_Redirect
, _T("Capture command &output...\tCtrl-O"),
421 _T("Launch a program and capture its output"));
422 execMenu
->Append(Exec_Pipe
, _T("&Pipe through command..."),
423 _T("Pipe a string through a filter"));
424 execMenu
->Append(Exec_POpen
, _T("&Open a pipe to a command...\tCtrl-P"),
425 _T("Open a pipe to and from another program"));
427 execMenu
->AppendSeparator();
428 execMenu
->Append(Exec_OpenFile
, _T("Open &file...\tCtrl-F"),
429 _T("Launch the command to open this kind of files"));
431 execMenu
->AppendSeparator();
432 execMenu
->Append(Exec_DDEExec
, _T("Execute command via &DDE...\tCtrl-D"));
433 execMenu
->Append(Exec_DDERequest
, _T("Send DDE &request...\tCtrl-R"));
436 wxMenu
*helpMenu
= new wxMenu(_T(""), wxMENU_TEAROFF
);
437 helpMenu
->Append(Exec_About
, _T("&About...\tF1"), _T("Show about dialog"));
439 // now append the freshly created menu to the menu bar...
440 wxMenuBar
*menuBar
= new wxMenuBar();
441 menuBar
->Append(menuFile
, _T("&File"));
442 menuBar
->Append(execMenu
, _T("&Exec"));
443 menuBar
->Append(helpMenu
, _T("&Help"));
445 // ... and attach this menu bar to the frame
448 // create the listbox in which we will show misc messages as they come
449 m_lbox
= new wxListBox(this, -1);
450 wxFont
font(12, wxFONTFAMILY_TELETYPE
, wxFONTSTYLE_NORMAL
,
451 wxFONTWEIGHT_NORMAL
);
453 m_lbox
->SetFont(font
);
456 // create a status bar just for fun (by default with 1 pane only)
458 SetStatusText(_T("Welcome to wxWindows exec sample!"));
459 #endif // wxUSE_STATUSBAR
462 // ----------------------------------------------------------------------------
463 // event handlers: file and help menu
464 // ----------------------------------------------------------------------------
466 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
468 // TRUE is to force the frame to close
472 void MyFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
477 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
479 wxMessageBox(_T("Exec wxWindows Sample\n© 2000-2002 Vadim Zeitlin"),
480 _T("About Exec"), wxOK
| wxICON_INFORMATION
, this);
483 void MyFrame::OnKill(wxCommandEvent
& WXUNUSED(event
))
485 long pid
= wxGetNumberFromUser(_T("Please specify the process to kill"),
489 // we need the full unsigned int range
498 static const wxString signalNames
[] =
500 _T("Just test (SIGNONE)"),
501 _T("Hangup (SIGHUP)"),
502 _T("Interrupt (SIGINT)"),
503 _T("Quit (SIGQUIT)"),
504 _T("Illegal instruction (SIGILL)"),
505 _T("Trap (SIGTRAP)"),
506 _T("Abort (SIGABRT)"),
507 _T("Emulated trap (SIGEMT)"),
508 _T("FP exception (SIGFPE)"),
509 _T("Kill (SIGKILL)"),
511 _T("Segment violation (SIGSEGV)"),
512 _T("System (SIGSYS)"),
513 _T("Broken pipe (SIGPIPE)"),
514 _T("Alarm (SIGALRM)"),
515 _T("Terminate (SIGTERM)"),
518 int sig
= wxGetSingleChoiceIndex(_T("How to kill the process?"),
520 WXSIZEOF(signalNames
), signalNames
,
525 wxFAIL_MSG( _T("unexpected return value") );
553 if ( wxProcess::Exists(pid
) )
554 wxLogStatus(_T("Process %ld is running."), pid
);
556 wxLogStatus(_T("No process with pid = %ld."), pid
);
560 wxKillError rc
= wxProcess::Kill(pid
, (wxSignal
)sig
);
561 if ( rc
== wxKILL_OK
)
563 wxLogStatus(_T("Process %ld killed with signal %d."), pid
, sig
);
567 static const wxChar
*errorText
[] =
570 _T("signal not supported"),
571 _T("permission denied"),
572 _T("no such process"),
573 _T("unspecified error"),
576 wxLogStatus(_T("Failed to kill process %ld with signal %d: %s"),
577 pid
, sig
, errorText
[rc
]);
582 // ----------------------------------------------------------------------------
583 // event handlers: exec menu
584 // ----------------------------------------------------------------------------
586 void MyFrame::DoAsyncExec(const wxString
& cmd
)
588 wxProcess
*process
= new MyProcess(this, cmd
);
589 m_pidLast
= wxExecute(cmd
, wxEXEC_ASYNC
, process
);
592 wxLogError( _T("Execution of '%s' failed."), cmd
.c_str() );
598 wxLogStatus( _T("Process %ld (%s) launched."),
599 m_pidLast
, cmd
.c_str() );
605 void MyFrame::OnSyncExec(wxCommandEvent
& WXUNUSED(event
))
607 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
614 wxLogStatus( _T("'%s' is running please wait..."), cmd
.c_str() );
616 int code
= wxExecute(cmd
, wxEXEC_SYNC
);
618 wxLogStatus(_T("Process '%s' terminated with exit code %d."),
624 void MyFrame::OnAsyncExec(wxCommandEvent
& WXUNUSED(event
))
626 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
636 void MyFrame::OnShell(wxCommandEvent
& WXUNUSED(event
))
638 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
645 int code
= wxShell(cmd
);
646 wxLogStatus(_T("Shell command '%s' terminated with exit code %d."),
651 void MyFrame::OnExecWithRedirect(wxCommandEvent
& WXUNUSED(event
))
653 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
661 switch ( wxMessageBox(_T("Execute it synchronously?"),
663 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this) )
679 wxArrayString output
, errors
;
680 int code
= wxExecute(cmd
, output
, errors
);
681 wxLogStatus(_T("command '%s' terminated with exit code %d."),
686 ShowOutput(cmd
, output
, _T("Output"));
687 ShowOutput(cmd
, errors
, _T("Errors"));
692 MyPipedProcess
*process
= new MyPipedProcess(this, cmd
);
693 if ( !wxExecute(cmd
, wxEXEC_ASYNC
, process
) )
695 wxLogError(_T("Execution of '%s' failed."), cmd
.c_str());
701 AddAsyncProcess(process
);
708 void MyFrame::OnExecWithPipe(wxCommandEvent
& WXUNUSED(event
))
711 m_cmdLast
= _T("tr [a-z] [A-Z]");
713 wxString cmd
= wxGetTextFromUser(_T("Enter the command: "),
720 wxString input
= wxGetTextFromUser(_T("Enter the string to send to it: "),
725 // always execute the filter asynchronously
726 MyPipedProcess2
*process
= new MyPipedProcess2(this, cmd
, input
);
727 long pid
= wxExecute(cmd
, wxEXEC_ASYNC
, process
);
730 wxLogStatus( _T("Process %ld (%s) launched."), pid
, cmd
.c_str() );
732 AddAsyncProcess(process
);
736 wxLogError(_T("Execution of '%s' failed."), cmd
.c_str());
744 void MyFrame::OnPOpen(wxCommandEvent
& event
)
746 wxString cmd
= wxGetTextFromUser(_T("Enter the command to launch: "),
752 wxProcess
*process
= wxProcess::Open(cmd
);
755 wxLogError(_T("Failed to launch the command."));
759 wxOutputStream
*out
= process
->GetOutputStream();
762 wxLogError(_T("Failed to connect to child stdin"));
766 wxInputStream
*in
= process
->GetInputStream();
769 wxLogError(_T("Failed to connect to child stdout"));
773 new MyPipeFrame(this, cmd
, process
);
776 void MyFrame::OnFileExec(wxCommandEvent
& event
)
778 static wxString s_filename
;
780 wxString filename
= wxLoadFileSelector(_T(""), _T(""), s_filename
);
784 s_filename
= filename
;
786 wxString ext
= filename
.AfterFirst(_T('.'));
787 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
790 wxLogError(_T("Impossible to determine the file type for extension '%s'"),
796 bool ok
= ft
->GetOpenCommand(&cmd
,
797 wxFileType::MessageParameters(filename
, _T("")));
801 wxLogError(_T("Impossible to find out how to open files of extension '%s'"),
809 // ----------------------------------------------------------------------------
811 // ----------------------------------------------------------------------------
815 bool MyFrame::GetDDEServer()
817 wxString server
= wxGetTextFromUser(_T("Server to connect to:"),
818 DIALOG_TITLE
, m_server
);
824 wxString topic
= wxGetTextFromUser(_T("DDE topic:"), DIALOG_TITLE
, m_topic
);
830 wxString cmd
= wxGetTextFromUser(_T("DDE command:"), DIALOG_TITLE
, m_cmdDde
);
839 void MyFrame::OnDDEExec(wxCommandEvent
& WXUNUSED(event
))
841 if ( !GetDDEServer() )
845 wxConnectionBase
*conn
= client
.MakeConnection("", m_server
, m_topic
);
848 wxLogError(_T("Failed to connect to the DDE server '%s'."),
853 if ( !conn
->Execute(m_cmdDde
) )
855 wxLogError(_T("Failed to execute command '%s' via DDE."),
860 wxLogStatus(_T("Successfully executed DDE command"));
865 void MyFrame::OnDDERequest(wxCommandEvent
& WXUNUSED(event
))
867 if ( !GetDDEServer() )
871 wxConnectionBase
*conn
= client
.MakeConnection("", m_server
, m_topic
);
874 wxLogError(_T("Failed to connect to the DDE server '%s'."),
879 if ( !conn
->Request(m_cmdDde
) )
881 wxLogError(_T("Failed to send request '%s' via DDE."),
886 wxLogStatus(_T("Successfully sent DDE request."));
891 #endif // __WINDOWS__
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
898 void MyFrame::OnIdle(wxIdleEvent
& event
)
900 size_t count
= m_running
.GetCount();
901 for ( size_t n
= 0; n
< count
; n
++ )
903 if ( m_running
[n
]->HasInput() )
910 void MyFrame::OnTimer(wxTimerEvent
& WXUNUSED(event
))
915 void MyFrame::OnProcessTerminated(MyPipedProcess
*process
)
917 RemoveAsyncProcess(process
);
921 void MyFrame::ShowOutput(const wxString
& cmd
,
922 const wxArrayString
& output
,
923 const wxString
& title
)
925 size_t count
= output
.GetCount();
929 m_lbox
->Append(wxString::Format(_T("--- %s of '%s' ---"),
930 title
.c_str(), cmd
.c_str()));
932 for ( size_t n
= 0; n
< count
; n
++ )
934 m_lbox
->Append(output
[n
]);
937 m_lbox
->Append(wxString::Format(_T("--- End of %s ---"),
938 title
.Lower().c_str()));
941 // ----------------------------------------------------------------------------
943 // ----------------------------------------------------------------------------
945 void MyProcess::OnTerminate(int pid
, int status
)
947 wxLogStatus(m_parent
, _T("Process %u ('%s') terminated with exit code %d."),
948 pid
, m_cmd
.c_str(), status
);
950 // we're not needed any more
954 // ----------------------------------------------------------------------------
956 // ----------------------------------------------------------------------------
958 bool MyPipedProcess::HasInput()
960 bool hasInput
= FALSE
;
962 if ( IsInputAvailable() )
964 wxTextInputStream
tis(*GetInputStream());
966 // this assumes that the output is always line buffered
968 msg
<< m_cmd
<< _T(" (stdout): ") << tis
.ReadLine();
970 m_parent
->GetLogListBox()->Append(msg
);
975 if ( IsErrorAvailable() )
977 wxTextInputStream
tis(*GetErrorStream());
979 // this assumes that the output is always line buffered
981 msg
<< m_cmd
<< _T(" (stderr): ") << tis
.ReadLine();
983 m_parent
->GetLogListBox()->Append(msg
);
991 void MyPipedProcess::OnTerminate(int pid
, int status
)
993 // show the rest of the output
997 m_parent
->OnProcessTerminated(this);
999 MyProcess::OnTerminate(pid
, status
);
1002 // ----------------------------------------------------------------------------
1004 // ----------------------------------------------------------------------------
1006 bool MyPipedProcess2::HasInput()
1010 wxTextOutputStream
os(*GetOutputStream());
1011 os
.WriteString(m_input
);
1016 // call us once again - may be we'll have output
1020 return MyPipedProcess::HasInput();
1023 // ============================================================================
1024 // MyPipeFrame implementation
1025 // ============================================================================
1027 MyPipeFrame::MyPipeFrame(wxFrame
*parent
,
1028 const wxString
& cmd
,
1030 : wxFrame(parent
, -1, cmd
),
1032 // in a real program we'd check that the streams are !NULL here
1033 m_in(*process
->GetInputStream()),
1034 m_out(*process
->GetOutputStream())
1036 m_process
->SetNextHandler(this);
1038 wxPanel
*panel
= new wxPanel(this, -1);
1040 m_textIn
= new wxTextCtrl(panel
, -1, _T(""),
1041 wxDefaultPosition
, wxDefaultSize
,
1042 wxTE_PROCESS_ENTER
);
1043 m_textOut
= new wxTextCtrl(panel
, -1, _T(""));
1044 m_textOut
->SetEditable(FALSE
);
1046 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1047 sizerTop
->Add(m_textIn
, 0, wxGROW
| wxALL
, 5);
1049 wxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
1050 sizerBtns
->Add(new wxButton(panel
, Exec_Btn_Send
, _T("&Send")), 0,
1052 sizerBtns
->Add(new wxButton(panel
, Exec_Btn_Get
, _T("&Get")), 0,
1055 sizerTop
->Add(sizerBtns
, 0, wxCENTRE
| wxALL
, 5);
1056 sizerTop
->Add(m_textOut
, 0, wxGROW
| wxALL
, 5);
1058 panel
->SetSizer(sizerTop
);
1059 sizerTop
->Fit(this);
1064 void MyPipeFrame::DoGet()
1066 // we don't have any way to be notified when any input appears on the
1067 // stream so we have to poll it :-(
1069 // NB: this really must be done because otherwise the other program might
1070 // not have enough time to receive or process our data and we'd read
1072 while ( !m_process
->IsInputAvailable() && m_process
->IsInputOpened() )
1075 m_textOut
->SetValue(m_in
.ReadLine());
1078 void MyPipeFrame::OnClose(wxCloseEvent
& event
)
1082 // we're not interested in getting the process termination notification
1083 // if we are closing it ourselves
1084 wxProcess
*process
= m_process
;
1086 process
->SetNextHandler(NULL
);
1088 process
->CloseOutput();
1094 void MyPipeFrame::OnProcessTerm(wxProcessEvent
& event
)
1099 wxLogWarning(_T("The other process has terminated, closing"));