home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!beowulf
- From: beowulf@titan.ucc.umass.edu (Peter Munson)
- Subject: Re: How can a program know where it was invoked?
- Message-ID: <1992Aug13.202855.12933@nic.umass.edu>
- Sender: usenet@nic.umass.edu (USENET News System)
- Nntp-Posting-Host: titan.ucc.umass.edu
- Organization: University of Massachusetts, Amherst
- References: <1992Aug9.025101.8559@ccsun7.csie.nctu.edu.tw> <bmckeon.713727455@unix1.tcd.ie> <1992Aug13.182509.10985@nic.umass.edu>
- Date: Thu, 13 Aug 1992 20:28:55 GMT
- Lines: 35
-
- In article <1992Aug13.182509.10985@nic.umass.edu> beowulf@titan.ucc.umass.edu (Peter Munson) writes:
- >In article <bmckeon.713727455@unix1.tcd.ie> bmckeon@unix1.tcd.ie (Brendan McKeon) writes:
- >>In <1992Aug9.025101.8559@ccsun7.csie.nctu.edu.tw> cp78085@csie.nctu.edu.tw (Tan Koan-Sin) writes:
- >>
- >>>Hello,
- >>> I would like to know how does a program knows where it was invoked?
- >>> For example,
- >>
- >>> foo file1
- >>
- >>> can foo detect where its binary execution file is?
- >>
- >>> Thanks.
- >>
- >>>--
- >>>Chin-Peng Choo
- >>
- [lots deleted]
-
- My answer was *much* too terse, I've been informed. What I should have
- said is that, since the command is usually on the user's $PATH, all you're
- going to get from argv[0] is the executable's name, not a full path.
- The only way out is to use which(1) or munge through the path yourself
- looking for it. Using which(1) is not a good idea, since it's expensive,
- can be fooled by links, and is not extremely portable.
- But it's not impossible, unless you need a guaranteed correct answer.
- So, 'no' was the wrong answer.
-
-
-
- --
- Peter Munson University Computing Services
- Systems Programmer University of Massachusetts
- beowulf@titan.ucc.umass.edu
- --All opinions expressed are neither mine nor my employer's--
-