Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Process continuously read output
From: Surya Kiran Gullapalli (suryakiran.gullapalli_at_[hidden])
Date: 2018-05-16 07:29:34


Well,
I do not know what is wrong with the question. I'm asking if this is the
right way to do the stuff with boost libraries. If I put this question
somewhere else, I'll be crucified for cross posting.

Surya.

On Wed, May 16, 2018 at 10:48 AM, degski via Boost-users <
boost-users_at_[hidden]> wrote:

> On 16 May 2018 at 05:11, Surya Kiran Gullapalli via Boost-users <
> boost-users_at_[hidden]> wrote:
>
>> Hi,
>> I'm trying to read outputs/logs from different processes and display them
>> in a GUI. The processes will be running for long time and produce huge
>> output. I'm planning to stream the output from those processes and display
>> them according to my needs. All the while allow my gui application to take
>> user inputs and perform other actions.
>>
>> What I've done here is, from main thread launch two threads for each
>> process. One for launching the process and another for reading output from
>> the process.
>>
>> This is the solution I've come up thus far.
>>
>> // Process Class
>> class MyProcess {
>> namespace bp = boost::process;
>> boost::asio::io_service mService; // member variable of the class
>> bp::ipstream mStream // member variable of the class
>> std::thread mProcessThread, mReaderThread // member variables of the
>> class.
>>
>> public void launch();
>> };
>>
>> void
>> MyProcess::launch()
>> {
>> mReaderThread = std::thread([&](){
>> std::string line;
>> while(getline(mStream, line)) {
>> std::cout << line << std::endl;
>> }
>> });
>>
>> mProcessThread = std::thread([&]() {
>> auto c = boost::child ("/path/of/executable", bp::std_out > mStream,
>> mService);
>>
>> mService.run();
>> mStream.pipe().close();
>> }
>> }
>>
>>
>> // Main Gui class
>> class MyGui
>> {
>> MyProcess process;
>> void launchProcess();
>> }
>>
>> MyGui::launchProcess()
>> {
>> process.launch();
>> doSomethingElse();
>> }
>>
>> The program is working as expected so far. But I'm not sure if this is
>> the correct solution. Please let me know if there's any
>> alternative/better/correct solution
>>
>
> There is a place to put/ask this kind of questions: https://codereview.
> stackexchange.com/
>
> degski
> --
> *"If something cannot go on forever, it will stop" - Herbert Stein*
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net