PDA

View Full Version : System Commands Output



nasir_qau
03-21-2002, 02:10 PM
I want to save the output of system command in the memory location.For example the following command will save the output in the file /tmp/lsfile.txt.

system("ls -al > /tmp/lsfile.txt");

Rather than saving it in file is it possible to save it in some string variable or any other data structure?Does any on know?

muttski
03-21-2002, 02:14 PM
There probly is, but if you want a temporary solution just load the file.

alex
03-21-2002, 03:14 PM
Yes there is. try this:


FILE *fp;

fp=popen("ls -al", "r");

/* read from "fp" using f***-functions */

pclose(fp);

alex