Running text based exe in new process

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Running text based exe in new process

Post by rakeshthp » Fri Dec 13, 2013 2:12 am

Hello,

I have two executable files. One is GUI based another is text based. I need to run the text based exe file from the GUI one. Of course, it needs to be run as a new process. At the same time I need the output of the text-based exe should be displayed in the main GUI exe. I am able to run that exe in new process. Wondering how to pass on it's output to the main window.

Any suggestions?

Thanks

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2465
Joined: Sun Jan 03, 2010 5:45 pm

Re: Running text based exe in new process

Post by PB » Fri Dec 13, 2013 6:29 am

Hello,

Perhaps you could take a look at wxWidgetss exec sample, I believe it demonstrates how to launch a command line tool and display its output, check out its menu command Exec/Capture command output .

Petr

rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Re: Running text based exe in new process

Post by rakeshthp » Fri Dec 13, 2013 7:51 am

Hi PB,

I have seen the sample program. I did implement it in my program the similar way. But the problem is that I need to execute a process in another thread. Not in the main thread. But wxExecute() complains me, it cannot be executed in non-main thread. How do I overcome this problem?

Thanks

Regards
Rakesh Patil

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2465
Joined: Sun Jan 03, 2010 5:45 pm

Re: Running text based exe in new process

Post by PB » Fri Dec 13, 2013 8:26 am

Sorry, I didn't notice you need to do that from the secondary thread. I have no idea how to do what you want then.

User avatar
doublemax
Moderator
Moderator
Posts: 14954
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Running text based exe in new process

Post by doublemax » Fri Dec 13, 2013 9:48 am

But wxExecute() complains me, it cannot be executed in non-main thread. How do I overcome this problem?
You can't. Send a message to the mainthread and start the exe from there.
Use the source, Luke!

rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Re: Running text based exe in new process

Post by rakeshthp » Fri Dec 13, 2013 10:57 am

Hi,

Why is that so? Theoretically also it is not possible, or with wxWidgets it is not possible? Can you point me to some examples of passing message to main thread? Is it available in sample/exec project?

Thanks

Regards
Rakesh Patil

User avatar
doublemax
Moderator
Moderator
Posts: 14954
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Running text based exe in new process

Post by doublemax » Fri Dec 13, 2013 11:14 am

Why is that so? Theoretically also it is not possible, or with wxWidgets it is not possible?
I only know that wxWidgets does not support it. I don't know if it's a platform limitation or an implementation limitation.
Can you point me to some examples of passing message to main thread?
http://docs.wxwidgets.org/trunk/classwx ... ef0318b59a

Sometimes this is easier:
http://docs.wxwidgets.org/trunk/classwx ... 50b3719519
Use the source, Luke!

rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Re: Running text based exe in new process

Post by rakeshthp » Fri Dec 13, 2013 11:20 am

I'll try with that one and get back to you.

Thanks

Regards
Rakesh Patil

rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Re: Running text based exe in new process

Post by rakeshthp » Wed Dec 18, 2013 11:36 am

Hello,

I was able to do it with the above mentioned links. Thanks a lot. Now the problem is that the response of mouse click is very slow. I have three buttons, one is the start the process, one is to pause it, and other one to stop the process. The output of the process is shown in the textbox of the main window. All three are working fine on my PC. On the other PC, with 3.00 GHz speed, I see the process is running very fast, and in the process if I happen to click pause, it will pause after few seconds, instead of pausing immediately.

The new process runs from the thread. And I call Pause() and Resume() functions of the thread to pause and resume. I also have used wxMilliSleep(500); after I invoke the worker thread event. Still the main window gets freezed on the other PC. Sorry couldn't post the entire code as it is very lengthy. But, other than Pause and Resume, most of the code is copied from the sample/thread.cpp program. Any Idea what might be going wrong?

Thanks

rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Re: Running text based exe in new process

Post by rakeshthp » Thu Dec 19, 2013 10:40 am

Hi doublemax,

Is the solution you gave here, applicable for my problem also? On 3GHz system, the main process (GUI) responses late for mouse events.

Any suggestions?

Thanks

Post Reply