我正在尝试读取给定目录中的所有文件(图片)并将其传递给 execv。我想启动帧缓冲图像查看器 (fbi)。
现在,当我从图片所在的目录启动它时,它可以工作。我如何操作矢量,使其不仅包含文件名,还包含路径+文件名?
int startSlideshow (char* pathtoFBI) {
pid_t fbiPid;
fbiPid = fork();
if (fbiPid == 0) {
/* this is the child process */
DIR *pictureDirectory;
struct dirent *dir;
int i = 0;
vector<char*> argVector;
char pDirectory[] = "/home/pi/bilder/";
argVector.push_back(pathtoFBI); /* first Argument is Program name */
pictureDirectory = opendir(pDirectory);
if (pictureDirectory){
while ((dir = readdir(pictureDirectory)) != NULL) {
i++;
if (i > 2) { /* first element is "." second is ".." */
argVector.push_back(dir->d_name);
}
}
//i -= 2;
} else ERREXIT("reading picture directory");
closedir(pictureDirectory);
argVector.push_back(NULL);
char** fbiArgv = &argVector[0];
execvp(pathtoFBI, fbiArgv); /* pid is taken over by fbi */
_exit(EXIT_FAILURE);
}