From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a1d846d0e0466c9b X-Google-Attributes: gid103376,public From: mfb@mbunix.mitre.org (Michael F Brenner) Subject: Re: Program (not task) Activation Date: 1998/04/24 Message-ID: <6hq561$fb4@top.mitre.org>#1/1 X-Deja-AN: 347297127 References: <#CDmPrma9GA.300@ntawwabp.compuserve.com> <6hjtju$kiq$1@owens.ridgecrest.ca.us> Summary: Confirming Jerry's code to spawn a main program Organization: The MITRE Corporation, Bedford Mass. Newsgroups: comp.lang.ada Date: 1998-04-24T00:00:00+00:00 List-Id: 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;