output redirection in Unix and C -
i trying run script inside c program using system() command. inside main(), run script , returns results. how can put result of script in string , check conditions? know can files wondering if possible put result string.
sample like:
main() { system("my_script_sh"); // how can result of my_script_sh }
you can't use system command that. best thing use popen:
file *stream; char buffer[150]; stream = popen("ls", "r"); while ( fgets(buffer, 150, stream) != null ){ // copy buffer output string etc. } pclose(stream);
Comments
Post a Comment