【发布时间】:2021-11-24 10:46:28
【问题描述】:
我正在尝试使用 c 中的系统从我的程序中运行特定的 c 程序。 gcc 告诉我“没有这样的文件或目录”,即使我把文件 在另一个程序目录中。目的是在第一个程序中达到某些条件时执行第二个程序。有什么帮助吗?
if(a==0){
system(" gcc -g -o iptablesExample mainiptables.c -lip4tc -lip6tc -ldl ");
system(" ./iptablesExample");
}
【问题讨论】:
-
iptablesExample的编译成功了吗?你能在进程的当前目录中找到它吗?在尝试执行之前添加system("ls");以查看当前目录中的文件。 -
是的,在shell中编译成功,文件不在正确的目录中!
-
您没有检查第一个
system命令的返回值(它应该为零)。如果你得到一个零,输出文件肯定存在。
标签: c shell gcc command system