Skip to contentSkip to conversation

DOS program recording it's parameters and environment?

DISCUSSION Frantisek Hanzlik 5 participants 11 messages Jan 18, 2012 – Feb 17, 2012 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Excuse me for slightly OT question. Know anyone DOS program, which is able record infos with what parameters was started and eventually other informations about calling environment (e.g. environment variables, available memory etc.)?

I've DOS program, which is optimized for run under windows, and this program is launching other its supplement programs, which are written for windows (e.g. search for updates and other access to internet, print to windows printers etc.). I'm running this program successfuly under DOSEMU and now I want run some its extension. Thus my questions:

1) Has someone any experience with this matters?

2) Program authors give me no iformations (except that they not support run program under Linux ;). My idea is uncover how are these external programs called and then run my own Linux equivalents. Then in first step i want small program which i can substitute instead of this windows one and see how is called from DOS program.
I was searching on internet, but found none - maybe i do not know construct right question.

Thanks in advance, Franta Hanzlik

#2 lore raw
In reply to a message not in the archive

Robert Supansic napsal(a):

Quoted 7 lines
Quoted 5 lines · Frantisek Hanzlik

Excuse me for slightly OT question. Know anyone DOS program, which is able record infos with what parameters was started and eventually other informations about calling environment (e.g. environment variables, available memory etc.)?

Quoted 5 lines

I do not know if I am understanding your question correctly, but there are two DOS commands that may help:
Both are run from the command line.

MEM /C /P will list available memory by type.
SET will list environmental variables.

Sorry for my bad english. I want program, which I arrange instead of windows program - which is started by my DOS program but I not know with what parameters.

For example: closed-source DOS program which i'm using start windows program WINPROG.EXE with parameters "C:\path\file /A delay=5". I not know these parameters, but when I take "spying" program, rename it to "WINPROG.EXE" and replace original program with him, then DOS program will run my "spying" program - and it can somewhere (e.g. to file) write info how was started (me interest mainly its parameters, but other informations, as available memory when was started, inherited environment variables, etc. would be welcomed).

Such "spying" program should be IMO very simple (sort of any copybook example) and perhaps already had someone this needs and realize it - but I cannot find it ;)

Or there is second way - write this itself. But I not know intel assembler, and use DJGPP C seems for me as "cannon onto sparrow". Or is there other publicly available programming language for DOS, which wil produce small code?

Thanks, Franta Hanzlik

#3 lore raw
Quoted 2 lines · On Wed, 18 Jan 2012 18:46:25 +0100 Frantisek Hanzlik wrote:

For example: closed-source DOS program which i'm using start windows program WINPROG.EXE with parameters "C:\path\file /A delay=5".

Have you considered using "strings progname.exe" and see what you can find that way? If the program isn't encrypted or compressed (with lzexe or whatever) you might find interesting things. And if it is compressed, you may discover how and be able to uncompress it.

Signature · 2 lines
MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com
www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER!
#4 lore raw
Quoted 10 lines · Frank Cox
Quoted 2 lines · On Wed, 18 Jan 2012 18:46:25 +0100 Frantisek Hanzlik wrote:

For example: closed-source DOS program which i'm using start windows program WINPROG.EXE with parameters "C:\path\file /A delay=5".

Have you considered using "strings progname.exe" and see what you can find that way? If the program isn't encrypted or compressed (with lzexe or whatever) you might find interesting things. And if it is compressed, you may discover how and be able to uncompress it.

There is violent that DOS program assemble parameters ("command line") for program which will execute dynamically, "strings" in this case will not be very usefull.

Help will be, when DOSEMU debug made this, but such details IMO there are not.

Franta

#5 lore raw
Quoted 7 lines · Frantisek Hanzlik
Quoted 6 lines · Frank Cox
Quoted 2 lines · On Wed, 18 Jan 2012 18:46:25 +0100 Frantisek Hanzlik wrote:

For example: closed-source DOS program which i'm using start windows program WINPROG.EXE with parameters "C:\path\file /A delay=5".

Quoted 7 lines
Quoted 2 lines

Have you considered using "strings progname.exe" and see what you can find that way?

There is violent that DOS program assemble parameters ("command line") for program which will execute dynamically, "strings" in this case will not be very usefull.

Franta,

I think that Frank is suggesting to use the "strings" not on WINPROG.EXE but on the closed-source DOS program that calls it. Wouldn't "strings" then show the command-lines which it is using? Maybe I'm way off base here....

Scott.

#6 lore raw
In reply to Frantisek Hanzlik

Dear Frantisek,

Quoted 4 lines

Excuse me for slightly OT question. Know anyone DOS program, which is able record infos with what parameters was started and eventually other informations about calling environment (e.g. environment variables, available memory etc.)?

Attacked is a gzip'd tar file with a simple program to do this, but re-named .dat instead of .tgz as we use Google mail and it is too stupid to allow compressed executables to be emailed.

Save to a Linux box and then re-name, then the usual arcive manager or tar can extract the files.

It creates a file dosenv.txt in the working directory and prints out the calling arguments and the environment to that file. If you have a C compiler (I used Microsoft's C6.0 DOS compiler from around 1988) you could modify this program to do other things (e.g. date/time based file names if they fit the 8.3 limit of DOS, etc)

Regards,
Paul

Signature · 8 lines
Dr. Paul S. Crawford
Satellite Station
Dundee University
Small's Wynd, Dundee,
DD1 4HN, U.K.
Tel: +44 (0)1382 38 4687
Email: [email protected]
The University of Dundee is a Scottish Registered Charity, No. SC015096
#7 lore raw

Paul Crawford napsal(a):

Quoted 13 lines

Dear Frantisek,

Quoted 4 lines

Excuse me for slightly OT question. Know anyone DOS program, which is able record infos with what parameters was started and eventually other informations about calling environment (e.g. environment variables, available memory etc.)?

Attacked is a gzip'd tar file with a simple program to do this, but re-named .dat instead of .tgz as we use Google mail and it is too stupid to allow compressed executables to be emailed.

Save to a Linux box and then re-name, then the usual arcive manager or tar can extract the files.

Quoted 8 lines

It creates a file dosenv.txt in the working directory and prints out the calling arguments and the environment to that file. If you have a C compiler (I used Microsoft's C6.0 DOS compiler from around 1988) you could modify this program to do other things (e.g. date/time based file names if they fit the 8.3 limit of DOS, etc)

Regards,
Paul

Hello Paul,

many thanks for Your help. I have not bigger piece of time for playing with until yesterday. And I must say You program work well, is quite tiny and when I have seen how it is simple, I was ashamed for being so powerless for writing similar code.

I was trying slightly modify You code (nothing much, only write result to not fixed name file, but to filename basename(argv[0]) and open it for append and write there timestamp when program run). Because I have not had any C compiler before, I was downloading and using OpenWatcom C compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock to problem - it seems as this compiler not support construction:

int main(int argc, char *argv[], char *envp[])

in the concrete, pointer to environment vector perhaps isn't possible or valid. Program compiles and links fine, run without problems, printed args are OK, but instead of environment variables it output only several weird characters. Thus, when I can still ask, know You or someone in DOSEMU or FreeDOS forum:

- when is possible walk through environment values in Watcom C? I think it may be possible with some undocumented functions, with some included assembler code etc. Or there may be problem e.g. in incorrect variable alignment in memory...? ;)

- or when there is other free DOS C compiler which would be possible use?

Thanks in advance, Franta Hanzlik

#8 lore raw

Dear Frantisek,

Quoted 4 lines

compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock to problem - it seems as this compiler not support construction:

int main(int argc, char *argv[], char *envp[])

I think this 3rd argument may be a MS-specific extension, as most C programs just have argc & argv in the call to main();

If you change to use the 'environ' variable, that should be pre-defined (probably in stdlib.h) and should do the same job. Attached is an example that seems to compile & work under C6 DOS compiler and with gcc on my Ubuntu 10.04 box.

Regards,
Paul

#include <stdio.h>
#include <stdlib.h>

extern char **environ;

int main(int argc, char *argv[])
{
int ii;
FILE *fp;
char **envp = environ;

	fp=fopen("dosenv.txt", "wb");
	if(fp != NULL)
		{
		fprintf(fp, "argc = %d\n", argc);

		for(ii=0; ii<argc; ii++)
			{
			fprintf(fp, "argv[%d] = %s\n", ii, argv[ii]);
			}

		ii=0;
		while(envp != NULL && envp[ii] != NULL)
			{
			fprintf(fp, "envp[%d] = %s\n", ii, envp[ii]);
			ii++;
			}

		fclose(fp);
		}

return 0;
}

#9 lore raw

Dear Paul,

You are right, it works with Watcom C fine. And now I found in "Watcom C Library Reference" manual paragraph:

environ
Prototype in <stdlib.h>.
This char ** __near data item is a pointer to an array of character pointers to the environment strings.

which I not noticed before. Eeh, I still must learn to much!

Many thanks once again,
Franta

Paul Crawford napsal(a):

Quoted 58 lines

Dear Frantisek,

Quoted 4 lines

compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock to problem - it seems as this compiler not support construction:

int main(int argc, char *argv[], char *envp[])

I think this 3rd argument may be a MS-specific extension, as most C programs just have argc & argv in the call to main();

If you change to use the 'environ' variable, that should be pre-defined (probably in stdlib.h) and should do the same job. Attached is an example that seems to compile & work under C6 DOS compiler and with gcc on my Ubuntu 10.04 box.

Regards,
Paul

dosenv.c

#include <stdio.h>
#include <stdlib.h>

extern char **environ;

int main(int argc, char *argv[])
{
int ii;
FILE *fp;
char **envp = environ;

	fp=fopen("dosenv.txt", "wb");
	if(fp != NULL)
		{
		fprintf(fp, "argc = %d\n", argc);

		for(ii=0; ii<argc; ii++)
			{
			fprintf(fp, "argv[%d] = %s\n", ii, argv[ii]);
			}

		ii=0;
		while(envp != NULL && envp[ii] != NULL)
			{
			fprintf(fp, "envp[%d] = %s\n", ii, envp[ii]);
			ii++;
			}

		fclose(fp);
		}

return 0;
}

#10 lore raw
In reply to Paul Crawford
Quoted 9 lines · Paul Crawford

Dear Frantisek,

Quoted 4 lines

compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock to problem - it seems as this compiler not support construction:

int main(int argc, char *argv[], char *envp[])

I think this 3rd argument may be a MS-specific extension, as most C programs just have argc & argv in the call to main();

This is not actually MS-specific; I see it in my execve(2) manpage here on Linux, and
<http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B> says "Unix (though not POSIX.1) and Microsoft Windows have a third argument giving the program's environment". (I was actually a little surprised to see that it wasn't POSIX.)

GNU's libc.info says so, too:

Quoted 10 lines

In Unix systems you can define `main' a third way, using three
arguments:

     int main (int ARGC, char *ARGV[], char *ENVP[])

The first two arguments are just the same. The third argument ENVP
gives the program's environment; it is the same as the value of environ'. See Environment Variables. POSIX.1 does not allow this three-argument form, so to be portable it is best to write main' to take two arguments, and use the value of `environ'.

#11 lore raw
Quoted 6 lines · Samuel Bronson
Quoted 5 lines · Paul Crawford

Dear Frantisek,

Quoted 3 lines

compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock to problem - it seems as this compiler not support construction:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

int main(int argc, char *argv[], char *envp[])

I think this 3rd argument may be a MS-specific extension, as most C programs just have argc & argv in the call to main();

This is not actually MS-specific; I see it in my execve(2) manpage here on Linux, and

Got curious and pulled down my "Let's C" (Mark Williams Company) manual from 1987.

envp - Argument passed to main

        char *envp[];

... and is by convention the third argument passed to main.

... Note that Let's C calls main(argc, argv, NULL); however, envp is significant under some other operating systems, including TOS, UNIX and COHERENT.

If of any interest.

Scott Swanson