linux - How to capture process output in C? -


is there analog of php's system in c?

man system says, system return status of command, need output (like in php).

of course, can use pipes this, there standard way?

you can make use of popen , related function as:

// command run. char *cmd = "date";   // open pipe stream. file *fp = popen(cmd,"r"); int ch;   // error checking. if(!fp) {         fprintf(stderr,"error popen %s\n",cmd);         exit(1); }     // read process , print. while((ch = fgetc(fp)) != eof) {         putchar(ch); }  // close stream. pclose(fp); 

ideone link


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -