system() question
Jonathan I. Kamens
jik at athena.mit.edu
Fri Feb 22 15:23:14 AEST 1991
In article <9321 at hub.ucsb.edu>, 6600bori at 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");
I have no idea why you get a coredump, and there's no way really for us to
tell. Have you attempted to analyze the coredump with a debugger to see what
it's from? Is it your process coredumping, or is it the shell that's being
started? I don't get a coredump on my machine. What type of machine are you
using, running what version of Unix?
In any case, I suspect that at least part of the problem is that the bourne
shell, which is what system uses, doesn't understand "~". Change the "~" to
"$HOME". Observe:
1 -> extern int system(char *);
2 -> system("last jik > ~/lastjik");
Linking from '/lib/libc.a' ... Linking completed.
sh: ~/lastjik: cannot create
(int) 256
3 -> system("last jik > $HOME/lastjik");
(int) 0
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.programmer
mailing list