Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!xylogics!transfer!crackers!m2c!ernie.viewlogic.com!news From: sparks@power.viewlogic.com (Alan Sparks) Newsgroups: comp.unix.internals Subject: Re: System() function Message-ID: <1990Oct23.213342.10037@viewlogic.com> Date: 23 Oct 90 21:33:42 GMT References: <24826@adm.BRL.MIL> Sender: news@viewlogic.com (News Administrator) Organization: Viewlogic Systems, Inc., Marlboro, MA Lines: 26 In article <24826@adm.BRL.MIL> vilva@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@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@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?