Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!bu-cs!bzs From: bzs@bu-cs.BU.EDU (Barry Shein) Newsgroups: comp.unix.questions Subject: Re: easy, basic, question... Message-ID: <36833@bu-cs.BU.EDU> Date: 21 Aug 89 02:21:30 GMT References: <11072@neon.Stanford.EDU> Organization: Boston U. Comp. Sci. Lines: 25 From: wolfe@neon.stanford.edu (Michael R. Wolfe) >I know how to call Unix commands from C: system(string), but >I'm having trouble coming up with the commands in string form >from inside of a program. That is, I'm being forced to do >multiple strcat's to form a string to send to system. Is there a >way around this? sprintf() should help a lot with this. >In addition, is there any way to find the result of a unix command >called from C without having to send it to a file and then open >the file. For example, I'm trying to use grep from C, which forces >me to make a string such as "grep file >> anotherfile" using strcat, >use "system" to call it, and then go and open "anotherfile" afterwards >to find the result. Has anyone come up with a better way? See popen(3) which returns a pipe to/from the command. -- -Barry Shein Software Tool & Die, Purveyors to the Trade 1330 Beacon Street, Brookline, MA 02146, (617) 739-0202 Internet: bzs@skuld.std.com UUCP: encore!xylogics!skuld!bzs or uunet!skuld!bzs