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);
Comments
Post a Comment