dimanche 15 mars 2015

how to show detailed file information under a directory in Linux Terminal? - C++


So this program supposed to print all of the file information under a directory. Below is my c++ code:



#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <sys/types.h>

using namespace std;

int main(int argc, char *argv[]){
execvp("/bin/ls",&argv[0]);
perror("failed to execute the command");
cout<< "The PID is " << getpid() <<endl;
return 0;
}


I think the command is supposed to be ls -a but how do I implement it in the program? Currently it only prints all of the files, not the information of each file.


Also how do I print the PID? Because the getpid() function doesn't seem to work.


Thank you!




Aucun commentaire:

Enregistrer un commentaire