找回密码
 注册
查看: 1723|回复: 2

GTK调用可执行程序

[复制链接]
发表于 2006-11-5 21:00:49 | 显示全部楼层 |阅读模式
各位大虾啊.
在GTK里面调用可执行文件怎么搞啊.比如己经有一个可执行文件, 然后有GTK编程里怎么样调用他, 另外如果想自己把它做成动态链接库,又应该怎么做呢.有没有这方面的书, 推荐一本.
小弟谢了先
发表于 2006-11-6 09:35:32 | 显示全部楼层
跟gtk关系不大,你看看《UNIX环境高级编程》吧
回复

使用道具 举报

发表于 2006-11-10 20:29:52 | 显示全部楼层
来自 hypersrc:

[code:1]
void
RunHelper(void)
{
    if ( !devhelpExists )
    {
        PrintStatusbar(_("*** devhelp not found"));
        return;
    }

    if ( IsAnyMajorFunctionBusy(TRUE))
    {
        return;
    }
    else
    if ( IsTextWidgetEmpty() || !ActiveModule() )
    {
        PrintStatusbar(_("Text widget is empty."));
        return;
    }
    gsize textLen = 0;
    gchar *pText = ActiveTextWidgetContents(&textLen);
    gint cursorIdx = OffsetAtCursor();
    if( cursorIdx < 0 || cursorIdx > textLen )
        return;

    // howto detect 'devehlp' exist?
    GString *wordAtCursor = ScoopWordAtCursor(MAX_WORD_LEN,
                            pText,
                            textLen,
                            cursorIdx);
    if ( NULL == wordAtCursor )
        return;

    gchar* sysargs[20]; // may be enough
    sysargs[0]="devhelp";
    sysargs[1]="--search";
    sysargs[2]=g_strdup(wordAtCursor->str);
    sysargs[3]=NULL;
   
    /*
     *run the helper and search 'str'
     */
    SysExec(sysargs[0], sysargs);
   
    g_string_free(wordAtCursor, TRUE);
    return;
}

/*****************************************************************************
* Execute a program (without waiting).
*****************************************************************************/
void
SysExec( char*  pFilename,
         char** ppExecArgs )
{
   pid_t        pid;

   pid = fork();

   if ( pid > 0 )
   {
     /*
      * This is the parent process.
      */
      return;      
   }
   else if ( pid == 0 )
   {
     /*
      * This is the child process.
      */
      execvp( pFilename, ppExecArgs );

     /*
      * exec*() isn't supposed to return.
      */
      Warning( "execvp('%s') failed.", pFilename );
      perror( "" );
      PrintStatusbarThirds( "Failed to invoke '", pFilename, "'." );
      _exit(-1); /* instead of exit() -- see GTK+ FAQ for why */
   }
   else /* pid < 0 */
   {
      Warning( "fork() failed." );
      perror("");
      return;
   }
}
[/code:1]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-6 14:22 , Processed in 0.044508 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表