easy, basic, question...

Barry Shein bzs at bu-cs.BU.EDU
Mon Aug 21 12:21:30 AEST 1989


From: wolfe at 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 at skuld.std.com
UUCP:     encore!xylogics!skuld!bzs or uunet!skuld!bzs



More information about the Comp.unix.questions mailing list