I am working on a project where I have to execute a command and print the output. Use popen, and it serves, but the output does not show the line breaks, if not, it shows everything as a single line.
My code:
#include <iostream>
#include <string.h>
#include <stdio.h>
int main () {
FILE *output;
string sys;
char line[200];
output = popen("ls -l", "r");
while ( !feof(output) ){
fgets(line, 180, output);
cout << line;
}
return 0;
}
the output it gives me is something like this:
-rw-r--r-- 1 root www-data 0 Sep 6 10:40 WebSS_06_Sep_10:40:19.in -rw-r--r-- 1 root www-data 0 Sep 6 10:40 WebSS_06_Sep_10:40:31.in -rw-r--r-- 1 root www-data 0 Sep 6 10:40 WebSS_06_Sep_10:40:32.in
but I'd like it to look like the console shows normally
-rw-r--r-- 1 root www-data 0 Sep 6 10:40 WebSS_06_Sep_10:40:19.in
-rw-r--r-- 1 root www-data 0 Sep 6 10:40 WebSS_06_Sep_10:40:31.in
-rw-r--r-- 1 root www-data 0 Sep 6 10:40 WebSS_06_Sep_10:40:32.in
I was thinking, maybe separate the chain each space and print 8 of those substrings in each line or I do not know if there is an easier way to do it.