www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/05/12:48:37

From: mauch AT uni-duisburg DOT de (Michael Mauch)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Determining the path of the executable at runtime
Date: Fri, 05 Sep 1997 17:13:59 +0200
Organization: Home, sweet home (via Gesamthochschule Duisburg)
Lines: 39
Message-ID: <34111de0.1882416@news.uni-duisburg.de>
References: <927cd$11e31 DOT 3dd AT news DOT eznet DOT net> <EFy4su DOT GBI AT fcshome DOT stoneham DOT ma DOT us>
NNTP-Posting-Host: ppp61.uni-duisburg.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Wed, 3 Sep 1997 19:00:28 GMT, fredex AT fcshome DOT stoneham DOT ma DOT us (Fred
Smith) wrote:

> On MSDOS >= 3.x, argv[0] is generally the full pathname of the program
> being run, which is either what you typed when you ran it, or based
> on a PATH search if you did not specify the absolute location. On 
> earlier systems argv[0] may be empty (I'm not sure). When run on
> Windoze I've no idea what argv[0] is. Unix platforms generally do
> not put the full pathname in argv[0], so you've got to make assumptions.
> One thing you can do is to search the PATH environment, but that for
> sure is not robust (what if you have a program named FOO in the path,
> but you instead ran a different program, from a different directory,
> of the same name??)

Section 12.1 of the DJGPP FAQ says:

| Note that the `argv[0]' parameter under the debugger is *not* the full
| pathname of the debuggee, so programs which use `argv[0]' for their 
| operation might behave differently under a debugger.

There's also something about stubedit and argv[0] in section 22.3.

I think that if the program was started by one of the spawn/exec
functions, it gets the contents of the argv0 parameter from the spawn
functions, and that doesn't have to be anything meaningful.

Hmm, tried it with

execlp("../c/argv0.exe", "something", "arg1", "arg2", 0);

=> the called program has "../c/argv0.exe" as its argv[0], "something"
is discarded.

execlp("argv0", "something", "arg1", "arg2", 0);
=> the called program has "argv0.exe" as its argv[0], no path at all.

Regards...
		Michael

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019