home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!destroyer!gatech!news.byu.edu!news.mtholyoke.edu!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.182509.10985@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>
- Date: Thu, 13 Aug 1992 18:25:09 GMT
- Lines: 34
-
- 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
- >
- >Hi,
- >
- >One way which works for me is to combine argv[0] ( the name of the file )
- >and the current working directory. A special case is made if argv[0] starts
- >with a '/'.
- >
-
- Tacking the name of the executable onto the directory from which it
- was _invoked_ will give you garbage unless you happen to be sitting in
- the same directory as the executable.
- The correct answer is 'no'.
- P.
-
- --
- 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--
-