使用您的 SPP 事物的 C 端,如果您可以访问 C 标头,那么简单的是使用类似的东西
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char* command = "ls";
char* args = "*.c";
char line[80];
sprintf( line, " %s %s\n", command, args );
system(line);
};
但是在 C 中dirent.h
,您可以找到执行此操作的函数。man opendir
在你的机器上试试
OPENDIR(3) Linux Programmer's Manual OPENDIR(3)
NAME
opendir, fdopendir - open a directory
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *name);
DIR *fdopendir(int fd);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
fdopendir():
Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
DESCRIPTION
The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer to
the directory stream. The stream is positioned at the first entry in the directory.
The fdopendir() function is like opendir(), but returns a directory stream for the directory referred to by
the open file descriptor fd. After a successful call to fdopendir(), fd is used internally by the implementa‐
tion, and should not otherwise be used by the application.
RETURN VALUE
...