GTK调用可执行程序
各位大虾啊.在GTK里面调用可执行文件怎么搞啊.比如己经有一个可执行文件, 然后有GTK编程里怎么样调用他, 另外如果想自己把它做成动态链接库,又应该怎么做呢.有没有这方面的书, 推荐一本.
小弟谢了先 跟gtk关系不大,你看看《UNIX环境高级编程》吧 来自 hypersrc:
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;
}
}
页:
[1]