使用system gcc命令从另一个运行c程序



我正试图从我的程序中运行一个特定的c程序。告诉我"没有这样的文件或目录"。即使我把文件在另一个程序目录中。目的是在第一个程序达到某些条件时执行第二个程序。任何帮助吗?

if(a==0){
system(" gcc -g -o iptablesExample mainiptables.c  -lip4tc -lip6tc -ldl ");
system(" ./iptablesExample");
}

也许您可以尝试使用execve和fork命令,但我不确定它是否有效

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>

int main(int ac, char **av, char **env) {
pid_t pid = fork();
char *args[] = {"/usr/bin/ls", "-la", NULL}; //put the absolute path of gcc
if (pid == 0)
{
if (execve(args[0], args, env) == -1)
perror("error");
}
wait(&pid);
return 0;
}

确保使用绝对路径