Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!ucbvax!agate!shelby!csli!poser From: poser@csli.Stanford.EDU (Bill Poser) Newsgroups: comp.lang.c Subject: Re: Contents of argv[0] Message-ID: <10148@csli.Stanford.EDU> Date: 19 Aug 89 21:59:57 GMT References: <9002@attctc.Dallas.TX.US> <1017@virtech.UUCP> <10094@csli.Stanford.EDU> <1935@ifi.uio.no> Reply-To: poser@csli.stanford.edu (Bill Poser) Organization: Center for the Study of Language and Information, Stanford U. Lines: 17 I don't know of a reliable way of finding out what directory an executable resides in from within a C program, but there is a reasonably simple way around this, which is to call the C program from a shell script that first records the directory in a file. I have a program that consists of three executables that do a sequence of overlays. (Don't ask why.) Rather than compile in the path name, I use the shell script trick. Here is the shell script: which $0 > .L3_loc $0_top $0 $* The "which" gets the full path name of the shell script and writes it into a temp file. The second line executes the top level C program and passes the arguments to it. The top level C program then reads the path name from the file. You could also pass the result of "which" as a command line argument.