c++ - 在 Firebreath 中使用个人程序

标签 c++ firebreath

我正在使用 Firebreath 构建一个插件。我在 ABCPluginAPI.cpp 中创建了一个名为 exe_program() 的个人方法,我想使用名为 my_program 的 popen 调用另一个程序。所有文件都在 firebreath/projects/ABCPlugin/中。

我的方法是:

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;
    }
}

我遇到的问题是插件没有运行 my_program,实际上如果我执行 pwd 命令,它会显示我的 $HOME 目录。 pwd 之所以有效,是因为它是一个通用命令,但我不想将我的程序放入 $PATH 变量中,因为这个插件必须是可移植的。

可能 Firebreath 使用特殊目录来指代此类文件或类似文件。

最佳答案

您可能需要指定要运行的应用程序的完整路径和文件名;当前工作目录不保证总是相同的值。

来自Tips and Tricks在 firebreath.org 的页面上,您可以将代码添加到 PluginCore 派生对象中,该对象将为您提供插件文件的完整路径和文件名:

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

您可以采用该路径,去掉最后一部分,并将其更改为您的可执行文件名;只要将可执行文件放在与插件相同的目录中就可以正常工作。或者,您可以将它安装在其他一些众所周知的位置。

请注意,要从您的 JSAPI 对象调用主插件对象的方法,您的 JSAPI 对象上应该有一个辅助方法 getPlugin()(如果您使用 fbgen 生成它):

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

希望对你有帮助

关于c++ - 在 Firebreath 中使用个人程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9858034/

相关文章:

c++ - 程序的意外输出

C++异常类设计

c++ - 使用来自另一个包的少量 C++ 级代码

c++ - 无法检测浏览器窗口中的点击以触发功能

c++ - 是否可以在同一个 dll 中有两个不同的插件

wix - 无法在 WiX 安装程序中显示对话框

C++字符串类效率

c++ - 重载 "->*"运算符

wix - 创建一个 msi 包,在一台机器上同时安装 32 位和 64 位资源

c++ - boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error>>