comp.lang.ada
 help / color / mirror / Atom feed
From: mfb@mbunix.mitre.org (Michael F Brenner)
Subject: Re: Program (not task) Activation
Date: 1998/04/24
Date: 1998-04-24T00:00:00+00:00	[thread overview]
Message-ID: <6hq561$fb4@top.mitre.org> (raw)
In-Reply-To: Eru8pD.4E@jvdsys.nextjk.stuyts.nl


This confirms that Jerry's demo program to call system works on 
gnat3.10 on NT 4.0 when you add a file cat.bat containing the string:
     TYPE %1

However, this code reflects the underlying runtime system's refusal to 
distinguish between:
    (CASE I) A program which runs and fails.
    (CASE II) A program which does not exist (say, program name spelt wrong) 

To show this, lines were added to demo.adb to test the following commands:

  (a) type an existing file:                                cat demo.adb
  (b) type a non-exiting file:                              cat demo.adZ
  (c) run an existing program that sets the condition code: exitcode 7
  (d) run a non-existing program:                           exitcodZ 7
  (e) run rabbits:                                          demo 

Result a:  (1) It typed the file demo.adb (as expected).
           (2) It returned condition code 0 (as expected).
           (3) It displayed no error messages (as expected).

Result b:  (1) It did not type the non-existing file (as expected).
           (2) It returned 1 (as expected). 
           (3) It printed the INCORRECT error message: The name 
               specified is not recognized as an internal or 
               external command, operable program or batch file.

Result c:  (1) It appeared to do nothing (as expected).
           (2) It returned condition code 7 (as expected).
           (3) It displayed no error messages (as expected).

Result d:  (1) It appeared to do nothing (as expected).
           (2) It returned condition code 1 (as expected).
           (3) It printed the CORRECT error message: The name
               specified is not recognized as an internal or
               external command, operable program or batch file.

Result e:  (1) It spawned itself, which spawned itself... (as expected).
           (2) Each of the spawned Selfs return condition code 0 (as expected).
           (3) It displayed no error messages until cancelled (as expected).

Jerry's code, and Jerry's demo with enhancements:

-- Commands.ads
package Commands is
   function System_Command (Argument : String) return Integer;
end Commands;

-- Command.adb
with Interfaces.C; use Interfaces.C;

package body Commands is

   function System (S : char_array) return int;
   pragma Import (C, System, "system");

   function System_Command (Argument : String) return Integer is
   begin
      return Integer (System (To_C (Argument)));
   end System_Command;

end Commands;
--
-- Jerry van Dijk  | email: jdijk@acm.org
-- Leiden, Holland | member Team-Ada
End of article 71031 (of 71034) -- what next? [npq]

-- demo.adb
with Commands; use Commands;
with text_io;
procedure Demo2 is
   Result : Integer;
begin
   Result := System_Command ("cat demo.adb");
   text_io.put_line ("The result of executing the command cat demo.adb was " &
                     integer'image (result));
   Result := System_Command ("cat demo.adZ");
   text_io.put_line ("The result of executing the command cat demo.adZ was " &
                     integer'image (result));
   Result := System_Command ("exitcode 1");
   text_io.put_line ("The result of executing the command was " &
                     integer'image (result));
   Result := System_Command ("demo");
   text_io.put_line ("The result of executing the command demo was " &
                     integer'image (result));

end Demo2;





  reply	other threads:[~1998-04-24  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-17  0:00 Program (not task) Activation Jeremy T Smith
1998-04-21  0:00 ` Robert I. Eachus
1998-04-21  0:00   ` Do-While Jones
1998-04-22  0:00     ` Jerry van Dijk
1998-04-24  0:00       ` Michael F Brenner [this message]
1998-04-27  0:00       ` Do-While Jones
1998-04-28  0:00         ` Jerry van Dijk
1998-04-29  0:00           ` Do-While Jones
1998-04-29  0:00             ` Do-While Jones
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox