delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/22/11:09:05

Date: Mon, 22 Jul 1996 18:03:33 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Orbital <vazndain AT pit DOT ktu DOT lt>
Cc: djgpp AT delorie DOT com
Subject: Re: bug in exec/spawn ?
In-Reply-To: <Pine.SOL.3.91.960722112637.25809A-100000@zalgiris>
Message-Id: <Pine.SUN.3.91.960722175413.8643F-100000@is>
Mime-Version: 1.0

On Mon, 22 Jul 1996, Martynas wrote:

> I wrote this program which loads its confguration file from the directory
> where the executable is. I use argv[0] to determine it. However, when my 
> program is invoked from make or rhide, it can never find the cfg file. I 
> wrote a little test prg, smth like puts(argv[0]); and when invoked from 
> make or rhide it displays *only* its name, *without* the path. What gives?

This is not a bug.  The child gets in argv[0] *exactly* what the parent
passes as the second argument to spawnXX function.  If the parent doesn't
bother to pass the full pathname there, the child won't get it.  This is
AFAIK how it should work.  I'm not entirely sure, but I think this is 
also so on Unix.

If you want your program to get its full pathname and argv[0] doesn't
include it, you could look for it along the PATH (e.g., with `searchpath'
library function; it looks in the current directory first).  Just be sure 
to do that before the program changes to another directory, if that could 
ever happen.

- Raw text -


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