how to execute external process better than wxExecute

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
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

how to execute external process better than wxExecute

Post by Jacek Poplawski » Fri Feb 17, 2012 11:08 pm

I execute external process this way:

Code: Select all

wxArrayString output;
wxExecute(command, output);
however, I have problem with it when I want to call:

Code: Select all

something >output
I need this output data, I tried wxExecute to achieve that but it's very very slow.
The output data is decoded photography in uncompressed format and it's about 60 megabytes.

It works correctly with:

Code: Select all

system("something >output")
but it's not very portable - on Windows it opens terminal window, and I don't want it

how to achieve it with wxExecute correctly?

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

Re: how to execute external process better than wxExecute

Post by doublemax » Fri Feb 17, 2012 11:32 pm

I've never used this myself, but from looking at the docs, these methods seems to do what you need:
http://docs.wxwidgets.org/stable/wx_wxp ... ssredirect
http://docs.wxwidgets.org/stable/wx_wxp ... nputstream

Also, check the "exec" sample.
Use the source, Luke!

Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

Re: how to execute external process better than wxExecute

Post by Jacek Poplawski » Mon Feb 20, 2012 6:45 pm

I tried to use this way:

Code: Select all

std::string command = std::string(DCRAW_EXECUTABLE) + " -w -c -6 -o 4 -W " + f + " >abc ";

wxProcess* process = wxProcess::Open(wxString::FromAscii(command.c_str()));

wxInputStream* input = process->GetInputStream();
and I found that:

1) InputStream "dies" somehow after reading part data I got LastRead smaller than expected, don't know what to do with that

2) when I omit ">abc" part in the command, the called application (in this case dcraw) thinks that the output is directed to terminal, that's why I use dummy ">abc", I wonder how does it work, why I can redirect this output to InputStream?

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

Re: how to execute external process better than wxExecute

Post by PB » Mon Feb 20, 2012 7:09 pm

I also have no experience with capturing process output, but ...
A stupid question: Have you checked out the exec sample bundled with wxWidgets to see how the output capturing is done there? Or is it done there the way that was uselessly slow?

What compiler and version of wxWidgets do you use? But this bug is probably not related to your speed problems anyway.

Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

Re: how to execute external process better than wxExecute

Post by Jacek Poplawski » Mon Feb 20, 2012 7:21 pm

I fixed the problem with read with following code:

Code: Select all

        int p = 0;

        while (p < w * 6)
        {
            input->Read(buffer + p, w * 6 - p);

            p += input->LastRead();

            if (p < w * 6)
            {
                std::cout << "wait for more data" << std::endl;
                wxThread::Sleep(10);
            }
        }

Post Reply