Printing command output

Hello, everybody.

I'm trying to print the output of a command through system() but appearantly my variable has a null value. Heres my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstdlib>
#include <ncurses.h>

int main(){
char command[] = "My command"
const char *str = (const char*) std::system(command);
int i = 0;

initscr();

while(1){
 system("sleep 1");
 mvprintw(i, 0, str); //mvprintw(i, 0, "%s", str) tells me that str is null.
 std::cout << "\r" << std::flush;
 i++;
 refresh();
}

endwin();
return 0;
}


And also, I'm kind of a newbie, could anyone tell me how to finish the program while it's executing? If I press Ctrl + Z it finishes because of the ncurses library but it only stops the process, it's still running on the background, then I have to kill the process manually.

I hope someone can give me a tip or guidance, thanks in advance! :D
Topic archived. No new replies allowed.