home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / programm / 4282 < prev    next >
Encoding:
Text File  |  1992-08-13  |  1.8 KB  |  48 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!beowulf
  3. From: beowulf@titan.ucc.umass.edu (Peter Munson)
  4. Subject: Re: How can a program know where it was invoked?
  5. Message-ID: <1992Aug13.202855.12933@nic.umass.edu>
  6. Sender: usenet@nic.umass.edu (USENET News System)
  7. Nntp-Posting-Host: titan.ucc.umass.edu
  8. Organization: University of Massachusetts, Amherst
  9. References: <1992Aug9.025101.8559@ccsun7.csie.nctu.edu.tw> <bmckeon.713727455@unix1.tcd.ie> <1992Aug13.182509.10985@nic.umass.edu>
  10. Date: Thu, 13 Aug 1992 20:28:55 GMT
  11. Lines: 35
  12.  
  13. In article <1992Aug13.182509.10985@nic.umass.edu> beowulf@titan.ucc.umass.edu (Peter Munson) writes:
  14. >In article <bmckeon.713727455@unix1.tcd.ie> bmckeon@unix1.tcd.ie (Brendan McKeon) writes:
  15. >>In <1992Aug9.025101.8559@ccsun7.csie.nctu.edu.tw> cp78085@csie.nctu.edu.tw (Tan Koan-Sin) writes:
  16. >>
  17. >>>Hello,
  18. >>>    I would like to know how does a program knows where it was invoked?
  19. >>>    For example, 
  20. >>
  21. >>>        foo file1
  22. >>
  23. >>>    can foo detect where its binary execution file is?
  24. >>
  25. >>>    Thanks.
  26. >>
  27. >>>--
  28. >>>Chin-Peng Choo
  29. >>
  30. [lots deleted]
  31.  
  32.   My answer was *much* too terse, I've been informed.  What I should have
  33. said is that, since the command is usually on the user's $PATH, all you're
  34. going to get from argv[0] is the executable's name, not a full path.
  35. The only way out is to use which(1) or munge through the path yourself
  36. looking for it.  Using which(1) is not a good idea, since it's expensive,
  37. can be fooled by links, and is not extremely portable. 
  38.   But it's not impossible, unless you need a guaranteed correct answer.
  39. So, 'no' was the wrong answer.
  40.  
  41.  
  42.  
  43. -- 
  44. Peter Munson                University Computing Services
  45. Systems Programmer          University of Massachusetts
  46. beowulf@titan.ucc.umass.edu 
  47. --All opinions expressed are neither mine nor my employer's--
  48.