我想在 C/C++ 程序中执行这个命令:stat -c "%F %A %n" *filename goes here*
文件名存储在main
函数的argv[1]
.
我试过了execl("/bin/stat", "stat", "-c", "\"%F %A %n\"", "file", NULL);
该命令应该如何execl()
实现结果?
您的命令应如下所示:
int res = execl("/bin/stat", "stat", "-c", "\"%F %A %n\"", argv[1], NULL);
if (res == -1) {
perror("/bin/stat");
exit(1);
}
然后 perror 会告诉你:
/bin/stat: No such file or directory
你会意识到 stat 在 /usr/bin 中,或者使用 execlp 是个好主意。
我发现了我的问题。该stat
命令位于/usr/bin
而不是/bin
.