Example of using popen in C

26. January 2012 08:00

 

A short code example of using popen in c to start a process then write to it using fprintf.

 

#include <stdio.h>


int main(int argc, char **argv) {
	FILE *fp = popen("cat", "w");
	int i = 0;

	for(i=0;i<10;i++)
		fprintf(fp, "Count = %d\n", i);

	pclose(fp);

	return 0;
}

E-mail Kick it! DZone it! del.icio.us Permalink


Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading