简体   繁体   中英

C - UNIX commands in program

I'm trying to create a program where it would count the number of directories, or the number of readable/writable/executable files. The user would input only the name of the author and the letters "d", "r", "w", or "x". I tried to directly call "ls -l" in my program but that caused an error. How do you call UNIX commands within a C program?

I tried to directly call "ls -l" in my program but that caused an error. How do you call UNIX commands within a C program?

You can se system in your C program, for example:

system( "ls -l" );

For that to work, you'll also need to #include <stdlib.h>

使用find命令可能会更好,可以使用命令“ find。-td | wc -l”对目录进行计数,并对带有适当标志的文件执行类似的操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM