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

  1. Newsgroups: comp.unix.programmer
  2. 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
  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.182509.10985@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>
  10. Date: Thu, 13 Aug 1992 18:25:09 GMT
  11. Lines: 34
  12.  
  13. In article <bmckeon.713727455@unix1.tcd.ie> bmckeon@unix1.tcd.ie (Brendan McKeon) writes:
  14. >In <1992Aug9.025101.8559@ccsun7.csie.nctu.edu.tw> cp78085@csie.nctu.edu.tw (Tan Koan-Sin) writes:
  15. >
  16. >>Hello,
  17. >>    I would like to know how does a program knows where it was invoked?
  18. >>    For example, 
  19. >
  20. >>        foo file1
  21. >
  22. >>    can foo detect where its binary execution file is?
  23. >
  24. >>    Thanks.
  25. >
  26. >>--
  27. >>Chin-Peng Choo
  28. >
  29. >Hi,
  30. >
  31. >One way which works for me is to combine argv[0] ( the name of the file )
  32. >and the current working directory. A special case is made if argv[0] starts
  33. >with a '/'.
  34. >
  35.  
  36.   Tacking the name of the executable onto the directory from which it
  37. was _invoked_ will give you garbage unless you happen to be sitting in
  38. the same directory as the executable.
  39.   The correct answer is 'no'.
  40. P.
  41.  
  42. -- 
  43. Peter Munson                University Computing Services
  44. Systems Programmer          University of Massachusetts
  45. beowulf@titan.ucc.umass.edu 
  46. --All opinions expressed are neither mine nor my employer's--
  47.