executing program name

G

gum

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

Vladimir S. Oka

gum said:
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
 
W

Walter Roberson

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?
 
M

Michael Mair

gum said:
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
 
C

CBFalconer

Vladimir S. Oka said:
gum said:
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
 
K

Kenneth Brody

Walter said:
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:[email protected]>
 
P

Peter Nilsson

Default said:
gum said:
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.
 
A

Arndt Jonasson

Vladimir S. Oka said:
gum said:
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.
 
W

Walter Roberson

Arndt Jonasson said:
Vladimir S. Oka said:
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.
 
P

Peter Shaggy Haywood

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 said:
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"?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top