Topic: Is argv[0] Specified to Contain the Filename of the Executable on


Author: Ron Natalie <ron@spamcop.net>
Date: Sat, 10 Feb 2001 11:45:14 GMT
Raw View

Jackson Yee wrote:
>
> Sorry for asking this question, but I don't have an up-to-date version of
> the standard at the moment.  What I'm looking for is whether argv[0] can be
> counted on to contain the filename of the program on all platforms such as
> Windows, Unix, and embedded systems, or if it is implementation-defined
> whether the filename is there or not.
>
Nope, the standard just says that it's the name used to invoke the program.
It's not necessarily a complete path.  It's not on UNIX where really argv[0]
is just what the caller passed to exec.  The shell usually gives what the
user typed so you don't get the full path.  Can't vouch for windows, but I
think it's the same (it is the command issued prior to the search).

In UNIX there is no good way to find the path to the executable.
In WINDOWS you can call SearchPath or other functions to determine this.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Ron Natalie <ron@spamcop.net>
Date: Sun, 11 Feb 2001 01:16:16 GMT
Raw View

sirwillard@my-deja.com wrote:
>
> In article <961j5u$e9v$1@solaris.cc.vt.edu>,
>
>
> At first glance the answer is yes, but if you read closely the answer
> is no.  It may be an empty string.

Even if a non-empty argv[0] is provided, the standard doesn't require it
to be the path to the executable.  It says the "name used to invoke the
program" which isn't (and has never been on any system I've used) the
full file path to the executable file.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]