繁体   English   中英

如何执行Xterm

[英]How to execl an Xterm

我想知道如何通过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没有显示出来。 我想知道出了什么问题。

如果对最近的xterm版本使用-hold (非+hold ),并且你的程序确实位于当前目录中(如"./shi" ),则应显示xterm。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM