Академический Документы
Профессиональный Документы
Культура Документы
t=20651
I'm a bit of a newb when it comes to C++ and I thought this would be simple to do
after looking at the exec example, but I still seem to be having problems. I am using
the structure provided by wxDev-C++.
CmdFrm.h
CODE: SELECT ALL
public:
CmdFrm(wxWindow *parent, wxWindowID id = 1, const wxString &title
= wxT("Cmd"), const wxPoint& pos = wxDefaultPosition, const wxSize&
size = wxDefaultSize, long style = Cmd_STYLE);
virtual ~CmdFrm();
void WxButton1Click(wxCommandEvent& event);
void WxButton2Click(wxCommandEvent& event);
private:
//Do not add custom control declarations between
//GUI Control Declaration Start and GUI Control Declaration End.
//wxDev-C++ will remove them. Add custom code after the block.
////GUI Control Declaration Start
wxButton *WxButton3;
wxButton *WxButton2;
wxTextCtrl *WxMemo3;
wxTextCtrl *WxEdit1;
1 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
wxTextCtrl *WxMemo2;
wxTextCtrl *WxMemo1;
wxButton *WxButton1;
wxPanel *WxPanel1;
////GUI Control Declaration End
wxProcess *MyProcess;
....
CmdFrm.cpp
CODE: SELECT ALL
void CmdFrm::CreateGUIControls()
{
//Do not add custom code between
//GUI Items Creation Start and GUI Items Creation End
...
The problem is, while the process seems to launch OK, it is not able to connect to
stdout. The same command I run works fine with the exec example.
Any ideas?
[SOLVED] DavidHart
Site Admin
by DavidHart » Wed Aug 20, 2008 10:24 am
Hi,
Posts: 3779
Joined: Thu Jan 12, 2006
One obvious problem with your code is that you don't seem actually to use wxExecute. 6:23 pm
AFAIK wxProcess isn't standalone, it's a helper for wxExecute. Location: IoW, UK
The 'exec' sample is rather overloaded. If you'd like to see my exec-derived code, have
a look at http://fourpane.svn.sourceforge.net/vie ... Dialog.cpp (which does what
you want without the confusion of too many extras).
Regards,
David
2 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
Hi,
Posts: 5
I wrote this minimal class which will output the stdout of the process. It runs the Joined: Wed Aug 20, 2008
process asynchronously, however, it blocks the window until the process is finished 1:22 pm
(still useful to follow a process being executed but having to wait for its completion).
It is certainly not very advanced (and probably it is better to use David's example) but
it is much easier to understand than the exec sample.
/*
* DisplayProcess.h
*
* Created on: 20-Aug-2008
* Author: zeb
*/
#ifndef DISPLAYPROCESS_H_
#define DISPLAYPROCESS_H_
#include "wx/wx.h"
#include "wx/process.h"
#include "wx/txtstrm.h"
/*
* DisplayProcess.cpp
*
* Created on: 20-Aug-2008
* Author: zeb
*/
#include "DisplayProcess.h"
if (process)
{
wxString log;
wxInputStream *msg = process->GetInputStream();
wxTextInputStream tStream(*msg);
while(!msg->Eof())
{
log = tStream.ReadLine();
tctrl->AppendText(log+wxT("\n"));
3 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
}
tctrl->AppendText(wxT("Finished!\n"));
} else {
tctrl->AppendText(wxT("FAIL: Command" + command + " could not be
run!\n"));
}
}
//....
m_textCtrl2->AppendText(wxT("All Finished!\n"));
delete dp;
Last edited by zeb on Thu Aug 21, 2008 8:36 am, edited 1 time in total.
to
CODE: SELECT ALL
and it works. Thanks for the insight on simpler ways to do this! Digging through the
exec sample is a bit tedious.
DanL wrote:
Thanks guys. Posts: 5
Joined: Wed Aug 20, 2008
1:22 pm
You're welcome. As you could see in my example, I also start to experiment with this,
since I need to redirect cygwin commands to my GUI.
May I ask, in which part of your code do you append the stream text in your WxMemo1
4 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
Thanks in advance.
DanL wrote:
I use the same method as in the piped example in the exec sample. I currently just Posts: 5
Joined: Wed Aug 20, 2008
have a button and in the event handler connect to the process and update the 1:22 pm
WxMemo. Does that make sense?
Alright, I'll have a deeper look to exec, thanks. Instead of a timer, you could have a
look at David "fourpan" example, who uses the fact that the process is idle to check
for the input and display it (it is still a timer though).
Last edited by zeb on Thu Aug 21, 2008 8:33 am, edited 1 time in total.
DavidHart wrote:
The 'exec' sample is rather overloaded. If you'd like to see my exec-derived code, Posts: 5
Joined: Wed Aug 20, 2008
have a look at http://fourpane.svn.sourceforge.net/vie ... Dialog.cpp (which does 1:22 pm
what you want without the confusion of too many extras).
David: I have some trouble trying to reuse the classes in ExecuteInDialog.cpp. Where
are AUTOCLOSE_FAILTIMEOUT and AUTOCLOSE_TIMEOUT defined ? I deactivated the
autoclose part to compile. Also I have instanciated a CommandDisplay but cannot
show it. This is an extract from main:
#include "wx/wxprec.h"
#include "ExecuteInDialog.h"
// [....]
bool MyApp::OnInit()
{
wxString cmd = "C:/cygwin/bin/ls.exe";
CommandDisplay *cd = new CommandDisplay();
5 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
Sorry, but (as you'll have noticed) the code is part of a larger project, and wasn't Posts: 3779
Joined: Thu Jan 12, 2006
really designed for easy reuse (yes I know, I should have). 6:23 pm
Location: IoW, UK
These were in a different header file:
CODE: SELECT ALL
CommandDisplay OutputDlg;
wxXmlResource::Get()->LoadDialog(&OutputDlg, NULL, wxT("OutputDlg"));
OutputDlg.Init( command );
OutputDlg.ShowModal();
if ( !OutputDlg.exitstatus )...
6 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxCheckBox" name="Autoclose">
<label>Auto-Close</label>
<checked>1</checked>
<tooltip>If checked, the dialog will automatically
close 2 seconds after the last entry is made</tooltip>
</object>
</object>
</object>
<option>1</option>
However if you aren't keen on XRC, you can make it yourself by putting a textctrl into
a dialog, so it looks like:
ATTACHMENTS
DavidHart wrote:
Hi Zeb, Posts: 5
Joined: Wed Aug 20, 2008
1:22 pm
Sorry, but (as you'll have noticed) the code is part of a larger project, and wasn't
really designed for easy reuse (yes I know, I should have).
Many thanks for this. I should be able to reuse XRC since I use (and learn)
wxFormBuilder which is particularly convenient. I am looking forward to try this.
Display posts from previous: All posts Sort by Post time Ascending Go
7 of 8 18/12/2018, 07:56
Using wxProcess and wxInputStream (and wxOutputStream) - wxWidge... https://forums.wxwidgets.org/viewtopic.php?t=20651
WHO IS ONLINE
Users browsing this forum: No registered users and 26 guests
Board index Contact us The team Delete all board cookies • All times are UTC
8 of 8 18/12/2018, 07:56