www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/03/21:27:47

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: System crashing - system( "readme.txt" );
Date: Tue, 03 Feb 1998 19:21:11 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 31
Message-ID: <34D7B477.6F21@cs.com>
References: <34D75A22 DOT C52E4737 AT swipnet DOT se>
NNTP-Posting-Host: ppp204.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Nils Anders Danielsson wrote:
> 
> When I run a program with something like "system( "readme.txt" );" in
> the code, the program crashes, both under Windows 95 and DOS 7.
> 
> Why?

Well, 'readme.txt' is not an executable file, so trying to "run" it via
system cannot possibly succeed.  I'm not sure if the library code traps
it as an error, but DOS certainly should.  In these cases, system()
should return -1 and set errno to the appropriate value.  As an absolute
worst case, the system could be instructed to "run" the file, and since
it doesn't contain valid instructions, your computer would crash.

Looking in the source code for system() doesn't entirely resolve this
question, but it's decidedly bad behavior.  In any case, I see no
internal check for a command's validity before attempting to run it.

> I'm writing a file manager with a command line function, and it's quite
> difficult to check if what's written is "runnable" or not.

The library function _is_executable() exists specifically for this
purpose.

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Animals can be driven crazy by pla- |
|       aka Fighteer I       | cing too many in too small a pen.    |
|   mailto:fighteer AT cs DOT com   | Homo sapiens is the only animal that |
| http://www.cs.com/fighteer | voluntarily does this to himself."   |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019