如何执行Xterm

3

我想知道如何通过execl调用Xterm。例如,以下代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include "util.h"
#define XTERM_PATH "/usr/bin/xterm"
#define XTERM "xterm"
int main() {
    int exStatus;
    pid_t childpid;
    childpid = fork();
    if ( childpid == -1 ) {
        perror( "Failed to fork" );
        exit( 0 );
    }
    if ( childpid == 0 ) {      // Child process

        exStatus = execl( XTERM_PATH, XTERM, "+hold", "-e", "./shi", "shi", (char *)NULL );
        if ( exStatus == -1 ) {
            perror( "Failed to execute shell" );
            exit( 0 );  
        }
    }
    else {
        wait(NULL);
    }   
    return 0; 
}

这里的shi是一个简单的程序,将HelloWorld打印到屏幕上。但在运行该程序后,Xterm并没有显示出来。我想知道出了什么问题。

1个回答

2
如果您在任何最近的xterm版本中使用-hold(而不是+hold),并且您的程序确实位于当前目录下(如"./shi"所示),那么xterm应该会显示出来。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接