executing program name

Discussion in 'C Programming' started by gum, Feb 1, 2006.

  1. gum

    gum Guest

    Other than argv[0] is there a way to obtain the name of the executable
    programatically?
    gum, Feb 1, 2006
    #1
    1. Advertising

  2. gum wrote:

    > Other than argv[0] is there a way to obtain the name of the executable
    > programatically?


    AFAIK, no, at least not portable. Why would you want to do it, though?

    Cheers

    Vladimir

    --
    Technological progress has merely provided us with more efficient means
    for going backwards.
    -- Aldous Huxley
    Vladimir S. Oka, Feb 1, 2006
    #2
    1. Advertising

  3. In article <aT7Ef.92780$>,
    gum <> wrote:
    >Other than argv[0] is there a way to obtain the name of the executable
    >programatically?


    What is the name of the executable that is running your microwave oven?
    --
    "It is important to remember that when it comes to law, computers
    never make copies, only human beings make copies. Computers are given
    commands, not permission. Only people can be given permission."
    -- Brad Templeton
    Walter Roberson, Feb 1, 2006
    #3
  4. gum

    Default User Guest

    gum wrote:

    > Other than argv[0] is there a way to obtain the name of the
    > executable programatically?


    What's wrong with that way?



    Brian
    Default User, Feb 1, 2006
    #4
  5. gum

    Michael Mair Guest

    gum wrote:
    > Other than argv[0] is there a way to obtain the name of the executable
    > programatically?


    .... and even argv[0] may be a null pointer.
    You may be hard pressed to find argv in the case of a freestanding
    implementation.

    However, your specific implementation (or: the environment /
    operating system) may provide another way. Ask in the respective
    newsgroups for more information.

    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Feb 1, 2006
    #5
  6. gum

    CBFalconer Guest

    "Vladimir S. Oka" wrote:
    > gum wrote:
    >
    >> Other than argv[0] is there a way to obtain the name of the
    >> executable programatically?

    >
    > AFAIK, no, at least not portable. Why would you want to do it,
    > though?


    And even that is not guaranteed. It is system dependant.

    --
    "The power of the Executive to cast a man into prison without
    formulating any charge known to the law, and particularly to
    deny him the judgement of his peers, is in the highest degree
    odious and is the foundation of all totalitarian government
    whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
    CBFalconer, Feb 2, 2006
    #6
  7. Walter Roberson wrote:
    >
    > In article <aT7Ef.92780$>,
    > gum <> wrote:
    > >Other than argv[0] is there a way to obtain the name of the executable
    > >programatically?

    >
    > What is the name of the executable that is running your microwave oven?


    Why, "a.out", of course! :)

    Your microwave may be different. :)

    --
    +-------------------------+--------------------+-----------------------------+
    | Kenneth J. Brody | www.hvcomputer.com | |
    | kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------------+
    Don't e-mail me at: <mailto:>
    Kenneth Brody, Feb 2, 2006
    #7
  8. Default User wrote:
    > gum wrote:
    > > Other than argv[0] is there a way to obtain the name of the
    > > executable programatically?

    >
    > What's wrong with that way?


    I can't speak for the OP, but if my "frobnosticator" program had a
    line...

    fprintf(stderr, "%s: bad vibes!\n", argv[0]);

    ....then on one system, it might print...

    C:\PROGRA~1\FROBNO~1\FROBNO~3.EXE: bad vibes!

    So, I generally never use argv[0] as the program name for non-trivial
    command line programs.

    --
    Peter
    Peter Nilsson, Feb 3, 2006
    #8
  9. "Vladimir S. Oka" <> writes:
    > gum wrote:
    >
    > > Other than argv[0] is there a way to obtain the name of the executable
    > > programatically?

    >
    > AFAIK, no, at least not portable. Why would you want to do it, though?


    Rather off-topic now, but the question deserves an answer. Here is one
    possible reason: a trick that's sometimes used is to create two
    different programs out of the same executable file. When the program
    starts, it determines from its name which one it is and handles its
    input accordingly. This makes sense if the different programs share a
    lot of code. It made even more sense in the early days of Unix, when
    disk usage must be kept low and so there was actually only one copy on
    disk, with "hard links" to the various names. 'mv', 'cp' and 'ln' are
    still implemented that way in Solaris.
    Arndt Jonasson, Feb 3, 2006
    #9
  10. In article <>,
    Arndt Jonasson <> wrote:

    >"Vladimir S. Oka" <> writes:
    >> gum wrote:


    >> > Other than argv[0] is there a way to obtain the name of the executable
    >> > programatically?


    >> AFAIK, no, at least not portable. Why would you want to do it, though?


    >Rather off-topic now, but the question deserves an answer. Here is one
    >possible reason: a trick that's sometimes used is to create two
    >different programs out of the same executable file. When the program
    >starts, it determines from its name which one it is and handles its
    >input accordingly.



    Vladimir's question was, it seems to me, "Why would you want to
    find the name of the executable using some method other than argv[0]?"

    Straying further:

    On systems with unix-like filesystems, there might not -be- one
    single name for an executable because multiple directory entries
    can point to the same inode (information node). Then there's small
    problems like loopback filesystems that introduce cycles into the
    name tree...

    On VMS, there might only be a single name in one sense, but it would
    seldom be the name that you would want, once you have taken into
    account clusters and "logicals"... e.g., you -probably- don't want to
    resolve the disk prefix all the way back to internal system notation.

    On some operating systems, the only meaningful "name" that a file
    might have might be its directory slot number, or might be its disk
    sector number.

    On Windows, you have to decide whether you want the long names
    or the short (DOS-compatible) names.

    And so on.
    --
    Prototypes are supertypes of their clones. -- maplesoft
    Walter Roberson, Feb 3, 2006
    #10
  11. Groovy hepcat Michael Mair was jivin' on Wed, 01 Feb 2006 22:28:33
    +0100 in comp.lang.c.
    Re: executing program name's a cool scene! Dig it!

    >gum wrote:
    >> Other than argv[0] is there a way to obtain the name of the executable
    >> programatically?

    >
    >... and even argv[0] may be a null pointer.


    Or it may point at an empty string.

    --

    Dig the even newer still, yet more improved, sig!

    http://alphalink.com.au/~phaywood/
    "Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
    I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
    Peter Shaggy Haywood, Feb 4, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    796
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,774
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,371
    Joe Smith
    Apr 22, 2007
  4. Shadow123
    Replies:
    0
    Views:
    278
    Shadow123
    Aug 11, 2008
  5. manish sahu
    Replies:
    11
    Views:
    752
    Keith Thompson
    Feb 13, 2010
Loading...

Share This Page