Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!csus.edu!ucdavis!csusac!usenet From: emmonsl@athena.ecs.csus.edu (L. Scott Emmons) Newsgroups: comp.unix.programmer Subject: Re: system() question Message-ID: <1991Mar2.181423.13981@csusac.csus.edu> Date: 2 Mar 91 18:14:23 GMT References: <9321@hub.ucsb.edu> Sender: usenet@csusac.csus.edu (News account (alt)) Distribution: comp Organization: California State University, Sacramento Lines: 32 In article <9321@hub.ucsb.edu> 6600bori@ucsbuxa.ucsb.edu (Boris Burtin) writes: >Can anyone tell me why I get a core dump >when I try to do : > > system("last [username] > ~/filename"); News has been stacked up here, so there's probably already been a reply to this (since it's been a week since your original post), but anyway... system() uses /bin/sh to execute the command, and sh doesn't know ~. Also, you are _much_ better off doing a fork() and then an exec() instead of a system()...system just does the equivalent of a fork() and an exec(), just _much_ less efficiently...If you need some help on using fork() and exec() please send me some mail and I'll be happy to give you a hand. (The reason that this is more efficient is because with exec() you don't fork a shell, you just execute the program directly). There is a story (well, a truth) around campus here. Someone needed to delete a file via a program. Instead of using unlink() they system("rm") the file... rm is just a program which calls unlink(), but with millions of times the overhead, because they used system() (ok, well not quite that much)...Anyway, avoid system() where exec() or a direct system call will do. Hope this offers you some help... L. Scott Emmons --------------- emmons@csus.csus.edu ...[ucbvax]!ucdavis!csus!emmons Packet: kc6nfp@kg6xx.#nocal.ca.usa.na