Xref: utzoo comp.unix.questions:31150 comp.lang.c:39141 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!mcsun!ukc!ox-prg!msc7.comlab!imc From: imc@prg.ox.ac.uk (Ian Collier) Newsgroups: comp.unix.questions,comp.lang.c Subject: Re: UNIX commands in C Message-ID: <751.imc@uk.ac.ox.prg> Date: 4 May 91 11:34:38 GMT References: <1991Apr28.153127.24926@jack.sns.com> <24527@well.sf.ca.us> Sender: news@prg.ox.ac.uk Reply-To: imc@prg.ox.ac.uk (Ian Collier) Organization: Oxford University Computing Laboratory, UK Lines: 27 In article , rearl@gnu.ai.mit.edu (Robert Earl) wrote: >In article <24527@well.sf.ca.us> ron@well.sf.ca.us (Ronald Hayden) writes: >| #include >| >| main () >| { >| printf("\nTesting the UNIX 'who' command --\n"); >| system("who"); >| printf("\nDone.\n"); >| exit(1); >| } >Since system() [and popen()] does an implicit fork, it's good practice >to explicitly flush output buffers before you call this routine; [etc] Also, that should really be "/bin/who" rather than just "who", unless you are going to set the path explicitly in the program. Otherwise the program could break on someone else's machine if they do not have /bin in their path (unlikely) or if some other random program called "who" appears before /bin/who in the path. If you do this in an suid program be absolutely certain to specify the path, or else this creates a security loophole. Ian Collier Ian.Collier@prg.ox.ac.uk | imc@ecs.ox.ac.uk