[comp.sys.ibm.pc] Program Loaded Where? from inside another

riml@softart.UUCP (Research in Motion Limited) (04/17/88)

[ when will messages be safe? ]

I have a program which invokes another program via an exec-type call
("system()" in C).  In mess-dos so far, this means your calling program
goes away until the new program has done its stuff.  My calling program
needs to know where the called program got loaded in memory.  Does
anyone have any hints on how to do this?  

As I see it, there are several possibilities:
1) write a "command.com" replacement to do the program load.  UGH!
2) intercept the DOS program exit function.  Messy but possible. Interferes
   with my program.
3) something else that I haven't realized yet.

Any help will be appreciated.  There might even be some free software
in it for you!

Thanks,
Michael A. Barnstijn	 uucp: ...!{decvax|ihnp4|utzoo|sun}!watmath!softart!riml
Research In Motion Limited   bell: (519) 888-7465
465 Phillip Street, Suite 6
Waterloo, Ontario, Canada
N2L 6C7

holtz@beowulf.ucsd.edu (Fred Holtz) (04/20/88)

In article <39@softart.UUCP> riml@softart.UUCP (Research in Motion Limited) writes:
>I have a program which invokes another program via an exec-type call
>("system()" in C).  In mess-dos so far, this means your calling program
>goes away until the new program has done its stuff.  My calling program
>needs to know where the called program got loaded in memory.  Does
>anyone have any hints on how to do this?  

An idea that may work for you is to reserve a special memory location in
the caller for the called program to patch its address into,  and then
passing the address of this area as a parameter to the called program, like:

Calling program:
  char *area, **temp, buf[64];
  temp = &area;
  sprintf(buf, "pgmname %lx", temp);
  system(buf);

Called program:
  char **area, *address;
  /* ...  set up the address */
  sscanf(av[1], "%lx", &area);
  *area = address;

Upon return from the called program the caller should now have its "area" set
to the called "address",  which I am not sure how to set,  but if your goal is
passing back a data structure or function address it is simple enough to do.
This will have to be done using a large memory and data model for both.
These code fragments may not work exactly as is (this is off the top of my
head),  but I think the general idea is workable.  My only question is why
do you want to do this in the first place?


Fred Holtz

ARPA:  holtz@sdcsvax.UCSD.EDU
UUCP:  sdcsvax!holtz

rmarks@KSP.Unisys.COM (richard marks) (04/21/88)

In article <39@softart.UUCP> riml@softart.UUCP (Research in Motion Limited) writes:
>I have a program which invokes another program via an exec-type call
>("system()" in C).  In mess-dos so far, this means your calling program
>goes away until the new program has done its stuff.  My calling program
>needs to know where the called program got loaded in memory.  Does
>anyone have any hints on how to do this?  

Try using the psp_parent segment at 0x2C into the called programs PSP.

Richard Marks
rmarks@KSP.unixyx.COM

dave@westmark.UUCP (Dave Levenson) (04/23/88)

In article <39@softart.UUCP>, riml@softart.UUCP (Research in Motion Limited) writes:
...
> I have a program which invokes another program via an exec-type call
> ("system()" in C).  In mess-dos so far, this means your calling program
> goes away until the new program has done its stuff.  My calling program
> needs to know where the called program got loaded in memory.  Does
> anyone have any hints on how to do this?  

I suggest that the calling program pass to the called program (as a
command line argument, or an environment setting) a far pointer to a
global variable.  The called program can than put a pointer to
itself (or its PSP or whatever you meant by the above) in the
location indicated by said pointer.  When it returns control to the
caller, the caller can find out where the called program was.

-- 
Dave Levenson
Westmark, Inc.		The Man in the Mooney
Warren, NJ USA
{rutgers | clyde | mtune | ihnp4}!westmark!dave