Mail Archives: djgpp/1997/05/01/13:30:50
On Thu, 1 May 1997, Paul Campisi wrote:
> I have a question about the System command. Whenever I call
> it and the file IS NOT an executable the whole program crashes. I know,
> you aren't supposed to be trying to execute the file in the first place,
> but isn't there a way to TRAP the error and not cause a crash if the
> program is not an executable? COMMAND.COM doesn't crash if you try
> to run CONFIG.SYS!
This is a DOS problem, not DJGPP's. When `system' tells DOS to run
CONFIG.SYS or any other non-executable file, DOS checks to see if it has
an MZ signature (meaning it's a .exe program) and if not, blindly assumes
that it is a .com executable, loads it and lets it "run", with quite
predictable results.
Btw, in my experience, COMMAND.COM could also crash that way. It depends
on the file you try to execute, and even with CONFIG.SYS, it depends on
what is its the content of.
`system' could of course test the program it is invoking for being an
excutable, but then it might refuse to run some rarely-used types of
executable files about which it doesn't know, because testing files for
being an executable is not easy at all. Try writing a program that does
that and see for yourself.
- Raw text -