gpt4 book ai didi

c - 如何执行 Xterm

转载 作者:行者123 更新时间:2023-12-02 01:28:08 27 4
gpt4 key购买 nike

我想知道如何通过 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)使用code> 版本,并且您的程序确实在当前目录中(如 "./shi" 所示),那么应该会显示一个 xterm。

关于c - 如何执行 Xterm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35808879/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com