Is there a way to run the linux command ls, from c++, and get all the outputs stored in one array, in c++?
Thanks
If you insist on actually running ls, you can use popen to launch the process and read the output:
FILE *proc = popen("/bin/ls -al","r");
char buf[1024];
while ( !feof(proc) && fgets(buf,sizeof(buf),proc) )
{
printf("Line read: %s",buf);
}
But you could probably better be reading the directory contents and file info yourself, using opendir and readdir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With