【问题标题】:How to run odaslive program from c file如何从c文件运行odaslive程序
【发布时间】:2018-12-17 01:37:39
【问题描述】:

所以我试图从我正在制作的 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);

}

【问题讨论】:

    标签: c++ execl


    【解决方案1】:

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

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

    检查返回值和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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-15
      • 2014-02-03
      相关资源
      最近更新 更多