0

所以我试图从我正在制作的 ac 文件中调用一个程序,但我能够做到这一点的唯一方法是使用 system() 函数,它本身会导致错误。在我使用的终端中运行程序;

~/odas/bin/odaslive -vc ~/odas/config/odaslive/matrix_creator.cfg

这就是我目前试图用来运行同一个程序的程序,它可以编译并将在终端中运行,但没有任何反应。

pid_t pid=fork();

if (pid==0){
    //static char *argv[] ={"echo","-vc ~/odas/config/odaslive/matrix_creator.cfg", NULL};
    execl("~/odas/bin", "~/odas/bin/odaslive", "-vc", "~/odas/config/odaslive/matrix_creator.cfg", (char *)NULL);
    exit(127);

} else {
    waitpid(pid,0,0);

}

4

1 回答 1

1

execl在第一个参数中需要文件路径。

它不会以家庭为路径扩展〜。必须提供完整路径。

检查返回值和errno。它会通知您失败的原因(如果有)。

int ret = execl("/home/username/odas/bin/odaslive", "/home/username/odas/bin/odaslive", "-vc", "/home/username/odas/config/odaslive/matrix_creator.cfg", (char *)NULL);
于 2018-12-17T02:09:00.387 回答