gpt4 book ai didi

c++ - 如何从c文件运行odaslive程序

转载 作者:行者123 更新时间:2023-11-28 04:27:57 25 4
gpt4 key购买 nike

所以我试图从我正在制作的 c 文件中调用一个程序,但我能够做到这一点的唯一方法是使用 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);

}

最佳答案

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);

关于c++ - 如何从c文件运行odaslive程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53808034/

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