System() function

Alan Sparks sparks at power.viewlogic.com
Wed Oct 24 07:33:42 AEST 1990


In article <24826 at adm.BRL.MIL> vilva at csvax.csc.lsu.edu (Vilva Natarajan) writes:
>
>I am trying to do system("man cat | wc -c") in my program, and i need
>to store the value returned by "wc" in a variable declared in my program.
>I dont want to redirect it to a file and then read from the file.
>Please advice.
>
>vilva at csvax.csc.lsu.edu


Use popen(1) and pclose(1).  Try something more like this:

	{
	  char retval[100];
	  FILE *pp;

	  pp = popen("man cat |wc -c","r");
	  fscanf(pp,"%s",retval);
	  pclose(pp);
	}

-- 

Alan Sparks      voice: (508) 480-0881  Internet: sparks at viewlogic.com
VIEWlogic Systems Inc., 293 Boston Post Rd. W., Marlboro MA 01752
Disclaimer: VIEWlogic didn't say this; I might have.  Who wants to know?



More information about the Comp.unix.internals mailing list