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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.160.36 with SMTP id xh4mr11576746pab.11.1385480127141; Tue, 26 Nov 2013 07:35:27 -0800 (PST) X-Received: by 10.49.106.100 with SMTP id gt4mr73997qeb.12.1385480127090; Tue, 26 Nov 2013 07:35:27 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.stack.nl!usenet-its.stanford.edu!usenet.stanford.edu!i10no1846991pba.1!news-out.google.com!p7ni1367qat.0!nntp.google.com!i2no6949593qav.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 26 Nov 2013 07:35:26 -0800 (PST) In-Reply-To: <1150031952.347657.244910@i40g2000cwc.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=178.85.93.94; posting-account=nZAcngoAAACcfYM9wDw3w9Z1XR3bObfs NNTP-Posting-Host: 178.85.93.94 References: <1150031952.347657.244910@i40g2000cwc.googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <78030be6-8fe4-4514-85fc-a2627507628f@googlegroups.com> Subject: Re: Is there some way of calling a system command? From: tolkamp Injection-Date: Tue, 26 Nov 2013 15:35:27 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:17791 Date: 2013-11-26T07:35:26-08:00 List-Id: Op zondag 11 juni 2006 15:19:12 UTC+2 schreef jimmaure...@worldnet.att.net: > Aldebaran wrote: > > I am a newbie Ada-programmer and need help with this topic. > > In C one can launch a system command, for instance through > > the following function. > > > > system("ls "); > > > > or in JAVA > > > > exec("ls"); > > > > Is there some similar way of calling a system command in ADA? > > The easiest way is to simply call the C system command. > The example below was run on my Windows XP system. > > with Interfaces.C.Strings; > use Interfaces.C.Strings; > > procedure System_Example is > function System_Call(Command : Chars_Ptr) return Interfaces.C.Int; > pragma Import(Convention => C, Entity => System_Call, > External_Name => "system"); > Rc : Interfaces.C.Int; > > begin > Rc := System_Call(New_String("dir")); > > end System_Example; > > The important part of the example is the creation of a function > specification I have named System_Call. That function specification > take a parameter of Chars_Ptr, which corresponds to a C char *. > The function specification is used as the Ada interface to the C > system call. The compiler is notified of that association through > the pragma Import. That pragma causes the compiler to link the C > system command and call it whenever System_Call is called in the > Ada code. > > Jim Rogers Thank you for your reaction. For me this is not very understandable. Where must I put the directory path to the executable? Is this "dir" in Rc := System_Call(New_String("dir"));?