Search code examples
c++firebreath

Use a personal program in Firebreath


I'm building a plugin using Firebreath. I made a personal method in ABCPluginAPI.cpp called exe_program() and I would like to call another program using popen called my_program. All the files are into firebreath/projects/ABCPlugin/.

My method is:

string ABCPluginAPI::exe_program()
{
    FILE * pPipe;
    fd_set readfd;
    char buff[1024];
    char command[128];
    int ret;

    strcpy(command, "my_program");

    if (!(pPipe = popen(command, "r"))) {
         // Problem to execute the command
       return "failed";
    }
    while(fgets(buff, sizeof(buff), pPipe)!=NULL){
        cout << buff;
        return buff;
    }
}

The problem I have is that the plugin is not running my_program, actually if I execute the pwd command, it shows my $HOME directory. pwd works because is a general command but I don't want to put my program into $PATH variable because this plugin must be portable.

Probably Firebreath use a special directory to refer to this kind of files or something similar.


Solution

  • You probably need to specify a full path and filename of the application you want to run; the current working directory is not garanteed to always be the same value.

    From the Tips and Tricks page of firebreath.org there is code you can add to your PluginCore-derived object that will give you the full path and filename of your plugin file:

    // From inside your Plugin class (that extends PluginCore)
    std::string MyPlugin::getFilesystemPath()
    {
        return m_filesystemPath;
    }
    

    You can take that path, strip off the last part, and change it to your executable filename; as long as you place the executable in the same directory as your plugin that should work fine. Alternately you could install it in some other well-known location.

    Note that to call a method on your main Plugin object from your JSAPI object there should be a helper method getPlugin() on your JSAPI object (if you used fbgen to generate it):

    std::string pluginPath = getPlugin()->getFilesystemPath();
    

    Hope that helps