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,71c49bb637416afe X-Google-Attributes: gid103376,public From: jerry@jvdsys.stuyts.nl (Jerry van Dijk) Subject: Re: "system" Call in GNAT? Date: 1999/04/05 Message-ID: #1/1 X-Deja-AN: 463065777 References: <3708E4C0.F13C2023@alphasoft-inc.com> Organization: * JerryWare *, Leiden, Holland Newsgroups: comp.lang.ada Date: 1999-04-05T00:00:00+00:00 List-Id: M. Smith (work@alphasoft-inc.com) wrote: : I was looking for a call in GNAT that would make invoke a command to the OS : for me and I found the function "system" and "execl". Calling the OS is, of course, OS specific, so not addressed by Ada or an Ada compiler (although a compiler may provided a vendor specific package for it). The system() call is the easiest to use, since you simply give it the command to execute in a string, and of it goes. However, the system() call is part of the C runtime library, not of the Win32 API, so you are making things more difficult than they need to be. Here is example: -- using the system call on Win32 to list a directory with System; -- to use the Address type procedure List is -------------------------------------------------------------------- procedure System_Call (S : in String) is -- The system() call is not part of the Win32 API, but of the C -- runtime library, which GNAT links in by default. -- Note that the system() call will go away and not return until -- its job is done. -- The return value of the system() call in the Win32 environment -- indicates the result of the system call, not the result of the -- command it tried to execute. Since system() is unlikely to -- fail I discard the return value here. procedure System_Call (Command : in System.Address); pragma Import (C, System_Call, "system"); -- The system() call expects a C string pointer, which is the -- address of the first character in a character array terminated -- by a zero. -- Note the distingishing between the Ada name (System_Call) and -- the C name (system) which are 'linked' by the import pragma. Command : constant String := S & ASCII.NUL; -- Add a terminating zero to the Ada string to make it look like -- a C string. begin System_Call (Command'Address); -- Command'Address returns the address of the first character end System_Call; ----------------------------------------------------------------------- begin System_Call ("dir"); end List; -- -- Jerry van Dijk | Leiden, Holland -- Team Ada | jdijk@acm.org -- see http://stad.dsl.nl/~jvandyk