[英]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".
用户仅输入作者的姓名和字母“ d”,“ r”,“ w”或“ x”。 I tried to directly call "ls -l" in my program but that caused an error.
我试图在程序中直接调用“ ls -l”,但这导致了错误。 How do you call UNIX commands within a C program?
您如何在C程序中调用UNIX命令?
I tried to directly call "ls -l" in my program but that caused an error.
我试图在程序中直接调用“ ls -l”,但这导致了错误。 How do you call UNIX commands within a C program?
您如何在C程序中调用UNIX命令?
You can se system
in your C program, for example: 您可以在C程序中设置
system
,例如:
system( "ls -l" );
For that to work, you'll also need to #include <stdlib.h>
为此,您还需要
#include <stdlib.h>
使用find命令可能会更好,可以使用命令“ find。-td | wc -l”对目录进行计数,并对带有适当标志的文件执行类似的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.