Re: spawn_async_with_pipes on windows using mingw (code atached)



Hi Armin,

Thank you for the reply. Finally I manage to compile the code. But now I'm stuck in a a runtime error. I put the command inside a try catch and the return shows a error number 2. Looking at glibmm api the error code 2 is for CHDIR. *

* http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1SpawnError.html#fb7753661f7b0607951aa8881380ed1b

I think the problem is at the string format. The new version of the code is bellow...

#include <iostream>
#include <gtkmm.h>
#include <glibmm.h>

class Player : public Gtk::Window
{
public:
    Player();
    virtual ~Player();
};

Player::Player()
{
    Glib::Pid _pid = 0;
    int _stdin = 0;
    int _stdout = 0;
    int _stderr = 0;

    typedef std::vector<std::string> strv_t;
    strv_t vector (5);
    vector[0] = "\"c:/mplayer/mplayer.exe\"";
    vector[1] = "\"-quiet\"";
    vector[2] = "\"-slave\"";
    vector[3] = "\"-idle\"";
    vector[4] = "\"c:/mplayer/truthhappens.ogg\"";

    try
    {
        Glib::spawn_async_with_pipes("\"c:/\"", vector, Glib::SpawnFlags(0), sigc::slot<void>(), &_pid, &_stdin, &_stdout, &_stderr);
    }
    catch (Glib::SpawnError e)
    {
        printf("Can't Spawn!!! spawn returns: %d\n", e.code());
        std::cout << "something went wrong!" << std::endl;
        system("sleep 10");
    }
   
    std::cout << "PID:    " << _pid << std::endl;
    std::cout << "STDIN:  " << _stdin << std::endl;
    std::cout << "STDOUT: " << _stdout << std::endl;
    std::cout << "STDERR: " << _stderr << std::endl;
   
    show_all_children();
}

Player::~Player()
{
}

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);
    Player player;
    Gtk::Main::run(player);

    return 0;
}

The compilation command still the same...

Thanks again for the support!
Paulo Flabiano Smorigo



On Sat, Sep 27, 2008 at 06:33, Armin Burgmeier <armin arbur net> wrote:
On Fri, 2008-09-26 at 17:59 -0300, Paulo Flabiano Smorigo wrote:
> Hi everybody,
>
> I'm still trying to compile spawn_async_with_pipes on windows. Now I
> created a little source that can help to solve the problem.
>
> I use the following command to compile (using gtkmm for windows
> libraries):
> i586-mingw32msvc-g++ Player.cpp `pkg-config --cflags --libs gtkmm-2.4`
> -o app.exe
>
> The code:
> #include <iostream>
> #include <gtkmm.h>
> #include <glibmm.h>
>
> class Player : public Gtk::Window
> {
> public:
>     Player();
>     virtual ~Player();
> };
>
> Player::Player()
> {
>     int _pid = 0;
>     int _stdin = 0;
>     int _stdout = 0;
>     int _stderr = 0;
>
>     char *vec[5];
>     vec[0] = "\"c:/mplayer/mplayer.exe\"";
>     vec[1] = "\"-quiet\"";
>     vec[2] = "\"-slave\"";
>     vec[3] = "\"-idle\"";
>     vec[4] = "\"c:/mplayer/truthhappens.ogg\"";
>
>     Glib::spawn_async_with_pipes("\"c:/\"", (char**) vec,
> Glib::SpawnFlags(0), sigc::slot<void>(), &_pid, &_stdin, &_stdout,
> &_stderr);
>
>     std::cout << "PID:    " << _pid << std::endl;
>     std::cout << "STDIN:  " << _stdin << std::endl;
>     std::cout << "STDOUT: " << _stdout << std::endl;
>     std::cout << "STDERR: " << _stderr << std::endl;
>     show_all_children();
> }
>
> Player::~Player()
> {
> }
>
> int main(int argc, char *argv[])
> {
>     Gtk::Main kit(argc, argv);
>     Player player;
>     Gtk::Main::run(player);
>
>     return 0;
> }
>
>
> And the error:
> Player.cpp: In constructor `Player::Player()':
> Player.cpp:26: error: no matching function for call to
> `spawn_async_with_pipes(const char[6], char**, Glib::SpawnFlags,
> sigc::slot<void, sigc::nil, sigc::nil, sigc::nil, sigc::nil,
> sigc::nil, sigc::nil, sigc::nil>, int*, int*, int*, int*)'
> /opt/gtk28win/include/glibmm-2.4/glibmm/spawn.h:147: note: candidates
> are: void Glib::spawn_async_with_pipes(const std::string&, const
> Glib::ArrayHandle<std::string,
> Glib::Container_Helpers::TypeTraits<std::string> >&, const
> Glib::ArrayHandle<std::string,
> Glib::Container_Helpers::TypeTraits<std::string> >&, Glib::SpawnFlags,
> const sigc::slot<void, sigc::nil, sigc::nil, sigc::nil, sigc::nil,
> sigc::nil, sigc::nil, sigc::nil>&, void**, int*, int*, int*)
> /opt/gtk28win/include/glibmm-2.4/glibmm/spawn.h:156: note:
> void Glib::spawn_async_with_pipes(const std::string&, const
> Glib::ArrayHandle<std::string,
> Glib::Container_Helpers::TypeTraits<std::string> >&, Glib::SpawnFlags,
> const sigc::slot<void, sigc::nil, sigc::nil, sigc::nil, sigc::nil,
> sigc::nil, sigc::nil, sigc::nil>&, void**, int*, int*, int*)
>
>
> Thanks in advance for the help...

PIDs are not simply integers on Windows, but pointers in fact (a HANDLE
for the created process). Glib provides the type Glib::Pid which should
be used for PIDs. This is an integer on linux, and a pointer on Windows.
So, try changing the type of _pid from int to Glib::Pid.

Furthermore, I don't think you can pass a simple C array as a
Glib::ArrayHandle to the spawn function (it would not know how many
entries there are in the array). Try using an STL container, such as
std::vector, instead:

Replace char *vec[5] by std::vector<std::string> vec(5)

> Paulo Flabiano Smorigo

Armin

> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]