home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mnemosyne.cs.du.edu!nyx!ebergman
- From: ebergman@nyx.cs.du.edu (Eric Bergman-Terrell)
- Subject: Re: How can a program know where it was invoked?
- Message-ID: <1992Aug12.141025.778@mnemosyne.cs.du.edu>
- X-Disclaimer: Nyx is a public access Unix system run by the University
- of Denver for the Denver community. The University has neither
- control over nor responsibility for the opinions of users.
- Sender: usenet@mnemosyne.cs.du.edu (netnews admin account)
- Organization: Nyx, Public Access Unix at U. of Denver Math/CS dept.
- References: <1992Aug9.024844.6230@debbie.cc.nctu.edu.tw> <31460023@hpcuhe.cup.hp.com>
- Date: Wed, 12 Aug 92 14:10:25 GMT
- Lines: 28
-
- In article <31460023@hpcuhe.cup.hp.com> jbc@hpcuhe.cup.hp.com (Jeff Caldwell) writes:
- >> I would like to know how does a program knows where it was invoked?
- >> For example,
- >> can foo detect where its binary execution file is?
- >
- >One rudimentary method is to use "system". Compile the following and run it:
- >
- > #include <stdlib.h>
- >
- > main(argc, argv)
- > int argc;
- > char *argv[];
- > {
- > char string[20];
- > sprintf(&string, "which %s", argv[0]);
- > system(string);
- > }
- >
- > -Jeff Caldwell
- >
-
-
- What about looking at argv[0]. Isn't this a reasonably portable way of
- ascertaining the pathname of the executable?
-
- Terrell
-
-
-