melling@cs.psu.edu (Michael D Mellinger) (06/24/91)
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? -Mike
darcy@druid.uucp (D'Arcy J.M. Cain) (06/24/91)
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 |
shaunc@gold.gvg.tek.com (Shaun Case) (06/25/91)
In article <1991Jun24.133431.10280@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes: >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: > ... assuming you are using a version of dos above 2.10, which does not support argv[0]. People are still using it, unfortunately. -- shaunc@gold.gvg.tek.com -- 100,000, perhaps 200,000 or more Iraqis died in a "Turkey Shoot" inappropriately called a "war." -- Michael Albert
Ralf.Brown@B.GP.CS.CMU.EDU (06/25/91)
In article <1991Jun24.133431.10280@druid.uucp>, darcy@druid.uucp (D'Arcy J.M. Cain) wrote: }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: }[...] }BTW this only works because COMMAND.COM puts it there. If you call your No, the kernel's EXEC function puts the program name there. But only in DOS 3.0 or higher. For DOS 2.x, you'll get an empty string as argv[0] under the C startups I'm familiar with. If the program is started with a relative path, you'll get that relative path in argv[0]; if a library function using a path search is involved, however, the program that DOS is asked to execute (and whose name is put in argv[0]) of necessity contains a path even if the original request didn't. -- {backbone}!cs.cmu.edu!ralf ARPA: RALF@CS.CMU.EDU FIDO: Ralf Brown 1:129/53 BITnet: RALF%CS.CMU.EDU@CARNEGIE AT&Tnet: (412)268-3053 (school) FAX: ask DISCLAIMER? Did | It isn't what we don't know that gives us trouble, it's I claim something?| what we know that ain't so. --Will Rogers
resnicks@netcom.COM (Steve Resnick) (06/26/91)
In article <2613@gold.gvg.tek.com> shaunc@gold.gvg.tek.com (Shaun Case) writes: >In article <1991Jun24.133431.10280@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes: >>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: >> > >... assuming you are using a version of dos above 2.10, which >does not support argv[0]. People are still using it, unfortunately. > SoapBox: On I would say to those running < DOS 3.1, "TOUGH!" We're THREE major releases and a good 6 years from the time when 2.1 was released. I can understand not fixing something that isn't broken, but if new software breaks it, then the old DOS is broken, not the new program. Were it the other way around, we would still be using dBASE II, Perfect Writer and Perfect Calc on CP/M machines, or worse yet, TRS DOS. SoapBox: Off Cheers! Steve -- ------------------------------------------------------------------------------- resnicks@netcom.com, steve@camphq, IFNA: 1:143/105.0, co moderator for comp.binaries.os2 Real life: Steve Resnick. Chief Software Architect, Process Scientific, Inc Flames, grammar and spelling errors >/dev/null The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2 -------------------------------------------------------------------------------
shaunc@gold.gvg.tek.com (Shaun Case) (06/26/91)
In article <1991Jun25.174819.7992@netcom.COM> resnicks@netcom.COM (Steve Resnick) writes: > >I would say to those running < DOS 3.1, "TOUGH!" We're THREE major >releases and a good 6 years from the time when 2.1 was released. I can >understand not fixing something that isn't broken, but if new software >breaks it, then the old DOS is broken, not the new program. Were it >the other way around, we would still be using dBASE II, Perfect Writer >and Perfect Calc on CP/M machines, or worse yet, TRS DOS. > Yes, but a pc running 2.10 is still a good usable machine (unlike some of examples above. :-) ) I have a friend with an AT&T 6300, with old ROMS. Until he upgrades his ROMS ($50 from AT&T) he is stuck with DOS 2.10, and 8k clusters. However, he is able to run 4DOS, Word Perfect, Turbo C, and has run a BBS on that system. All that aside, it's still good to keep in mind that argv[0] doesn't work under Dos 2.10 when you are writing a program for a client who happens to be running 2.10, and is unwilling or unable to upgrade. It's not a flame, it's just something you should keep in mind. (I use argv[0], and when Spike tries to run my programs they fail on the first go round.) If you want your software to run on the widest possible variety of machines, just take that into account, just like not masking the 8th bit. Beware of blind one handed Icelandic hackers using dos 2.10 and an xt-style keyboard! ;-) ;-) ;-) Shaun. -- shaunc@gold.gvg.tek.com -- 100,000, perhaps 200,000 or more Iraqis died in a "Turkey Shoot" inappropriately called a "war." -- Michael Albert
mrs@netcom.COM (Morgan Schweers) (06/26/91)
Some time ago darcy@druid.uucp (D'Arcy J.M. Cain) happily mumbled: >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: This is true in operating systems other than DOS, I believe. Unix, for example. > [Code removed] > >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. > I'm working on it. *evil grin* > >-- >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 | -- Morgan Schweers -- mrs@netcom.com | Morgan Schweers | Good code, good food, good sex. Is ms@gnu.ai.mit.edu| These messages | anything else important? -- Freela Kilroy Balore | are not the +-------------------------------------- Freela | opinion of anyone.| I *AM* an AI. I'm not real...
derek@sun4dts.dts.ine.philips.nl (derek) (06/26/91)
resnicks@netcom.COM (Steve Resnick) writes: >In article <2613@gold.gvg.tek.com> shaunc@gold.gvg.tek.com (Shaun Case) writes: >>In article <1991Jun24.133431.10280@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes: >>>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: >>> >> >>... assuming you are using a version of dos above 2.10, which >>does not support argv[0]. People are still using it, unfortunately. >> >SoapBox: On >I would say to those running < DOS 3.1, "TOUGH!" We're THREE major >releases and a good 6 years from the time when 2.1 was released. I can >understand not fixing something that isn't broken, but if new software >breaks it, then the old DOS is broken, not the new program. Were it >the other way around, we would still be using dBASE II, Perfect Writer >and Perfect Calc on CP/M machines, or worse yet, TRS DOS. >SoapBox: Off >Cheers! >Steve >-- >------------------------------------------------------------------------------- > resnicks@netcom.com, steve@camphq, IFNA: 1:143/105.0, > co moderator for comp.binaries.os2 > Real life: Steve Resnick. Chief Software Architect, Process Scientific, Inc > Flames, grammar and spelling errors >/dev/null > The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2 >------------------------------------------------------------------------------- I don't think that's so good an attitude - some people are forced into using the dos they have. Compromize is the name of the game. If the user has a low numbered Dos, they have to make a couple of sacrifices for you (just don't forget to mention that in the documentation). The files must be: 1. In the current directory 2. In the root of the current drive (easiest for floppy users) 3. Defined in an environment variable. You could also check the path. None of this is particularly difficult to do: Check the dos version if ver < 3.1 /* or something */ check for environment variable if not found check for file in current directory if not found check for file in root if not found, exit gracefully. Don't forget to tell the user he shouldn't rename the file ( dos <) So - tell me why you shouldn't take these simple steps to make all potential users happy, and I'll tell you, or rather they'll tell you what you can do with your software. (Irony alert!) Best Regards, Derek Carr DEREK@DTS.INE.PHILIPS.NL Philips IE TQV-5 Eindhoven, The Netherlands Standard Disclaimers apply.
tarjeij@ulrik.uio.no (Tarjei Jensen) (06/27/91)
I think that files should be searched for as follows. if environment variable set then use it if file found goto success if path in argv[0] then use it if file found goto success use current directory if file found goto success use hardwired path if file found goto success :failed exit gracefully or use reasonable defaults :success do whatever you want Please note that the goto need not be taken literally (please). I think one should be able to expect users to have a late version of MSDOS. If we don't we are not going to get anywhere. It will become difficult to phase out bad habits (e.g. writing directly to the screen) and use new tricks. I feel sorry for people that cannot upgrade, but everybody can't stand still just for those few. In other words; if msdos v5 proves to be good, then I expect that I will have to upgrade to that version in order to use new software. I think that is reasonable. Greetings from Norway, -- // Tarjei T. Jensen - if it ain't broken, fix it anyway! // tarjeij@ulrik.uio.no || +47 87 21138 // Working, but not speaking for the Norwegian National Library.
resnicks@netcom.COM (Steve Resnick) (06/28/91)
In article <745@sun4dts.dts.ine.philips.nl> derek@sun4dts.dts.ine.philips.nl (derek) writes: >resnicks@netcom.COM (Steve Resnick) writes: [Stuff deleted] >>SoapBox: On > >>I would say to those running < DOS 3.1, "TOUGH!" We're THREE major >>releases and a good 6 years from the time when 2.1 was released. I can >>understand not fixing something that isn't broken, but if new software >>breaks it, then the old DOS is broken, not the new program. Were it >>the other way around, we would still be using dBASE II, Perfect Writer >>and Perfect Calc on CP/M machines, or worse yet, TRS DOS. > >>SoapBox: Off > > >>Cheers! >>Steve [My .sig deleted] >I don't think that's so good an attitude - some people are forced into using >the dos they have. Compromize is the name of the game. If the user has a >low numbered Dos, they have to make a couple of sacrifices for you (just >don't forget to mention that in the documentation). The files must be: >1. In the current directory >2. In the root of the current drive (easiest for floppy users) >3. Defined in an environment variable. > >You could also check the path. >None of this is particularly difficult to do: >Check the dos version >if ver < 3.1 /* or something */ >check for environment variable >if not found >check for file in current directory >if not found >check for file in root >if not found, exit gracefully. > >Don't forget to tell the user he shouldn't rename the file ( dos <) > >So - tell me why you shouldn't take these simple steps to make all potential >users happy, and I'll tell you, or rather they'll tell you what you can do >with your software. (Irony alert!) All of the software I write for work requires file sharing, so if you run DOS <3.1 it's a moot point. It cannot be done. Most of the rest of the software I write uses DOS functions and services not available in <3.0 I try and maintain compatibility with at least 1 major revision behind the current. From a professional aspect, I can't support older DOS versions, because *My Support* ends at the previous versions of DOS. (Just try and call MS and ask for support for DOS 2). Take the argument from the other side, and I can give you a number of reasons to continue to run DOS 1.1 (Which I still have a copy of somewhere) It's a tiny OS, and doesn't have the same kind of overhead ver >= 2 has, as well as having a simpler disk structure. Seriously, though, I don't think it's unreasonable to ask users to run an operating system that's 5 or less years old. Additionally, I have not encountered anyone who has complained of anything I have written not running because of the DOS version. For me, the bottom line is, how much will it cost me to maintain compatibility with DOS 2, versus how much it will gain me to do so. The apparent cost is time, the apparent benefit, for me, is none. This may be different for other programmers, and more power to them, but for me, it's a non-issue. Cheers! Steve -- ------------------------------------------------------------------------------- resnicks@netcom.com, steve@camphq, IFNA: 1:143/105.0, co moderator for comp.binaries.os2 Real life: Steve Resnick. Chief Software Architect, Process Scientific, Inc Flames, grammar and spelling errors >/dev/null The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2 -------------------------------------------------------------------------------