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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e86fb8cc090152ea X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!feeder.news-service.com!feeder2.cambrium.nl!feed.tweaknews.nl!news.astraweb.com!newsrouter-eu.astraweb.com!proxad.net!cleanfeed2-b.proxad.net!nnrp4-2.free.fr!not-for-mail From: "Michel Simeon" Newsgroups: comp.lang.ada References: <1150031952.347657.244910@i40g2000cwc.googlegroups.com> Subject: Re: Is there some way of calling a system command? Date: Thu, 15 Jun 2006 16:03:12 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Message-ID: <449168a1$0$9944$636a55ce@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 15 Jun 2006 16:03:13 MEST NNTP-Posting-Host: 82.251.206.118 X-Trace: 1150380193 nnrp4-2.free.fr 9944 82.251.206.118:1430 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:4788 Date: 2006-06-15T16:03:13+02:00 List-Id: I am learning Ada and does not know C. I tried your approach to call an othe program from Ada and it worked, except for one problem: the calling program will wait for the return parameter (Rc in your exemple) and thus freeze till the other one is closed. Could i do something similar but withour the retrun parameter ? -- Michel Simeon wrote in message news:1150031952.347657.244910@i40g2000cwc.googlegroups.com... > 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 >