🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7301

Re: Where's the executable located?

#7301
From: D'Arcy J.M. Cain
Date: Mon, 24 Jun 1991 13:34
31 lines
1799 bytes
In <i8Hrm1=@cs.psu.edu> melling@cs.psu.edu (Michael D Mellinger) writes:
>If my program is in someone's path, how can I tell where it's located
>so that I can get the supporting files that are needed with it?

This is real easy in DOS.  argv[0] is the full pathname of the invoking
process.  I often do something like this:

  char	config[64], *p;
  strcpy(config, argv[0]);
  if ((p = strchr(config, '.')) != NULL)
    *p = 0;
  strcat(config, ".CFG");

Now I can have a program act differently just by copying it to another
name and creating a new config file.  Now if only DOS used file links
like Unix I wouldn't waste disk space doing so.

BTW this only works because COMMAND.COM puts it there.  If you call your
program from another program this may not work.  In fact argv[0] may
have total garbage in it.  It is up to the program calling the exec
function to fill in that field.  So today's tip is:  If you are writing
a program that uses one of the exec calls make sure the full path name
of the called process is in the second argument.  This usually simply
means that you repeat the first argument verbatim unless you use one
of the "p" versions of the call.

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   There's no government
Toronto, Ontario, Canada           |   like no government!
+1 416 424 2871                    |
Technical Details
Message-ID: <1991Jun24.133431.10280@druid.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!lethe!druid!darcy
References: <i8Hrm1=@cs.psu.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!lethe!druid!darcy
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: Re: Where's the executable located?
Message-ID: <1991Jun24.133431.10280@druid.uucp>
Organization: D'Arcy Cain Consulting, West Hill, Ontario
References: <i8Hrm1=@cs.psu.edu>
Distribution: comp
Date: Mon, 24 Jun 91 13:34:31 GMT