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.158.6 with SMTP id wq6mr1283077pab.39.1385492078218; Tue, 26 Nov 2013 10:54:38 -0800 (PST) X-Received: by 10.182.246.133 with SMTP id xw5mr324074obc.14.1385492078146; Tue, 26 Nov 2013 10:54:38 -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.glorb.com!i10no1936555pba.1!news-out.google.com!9ni5285qaf.0!nntp.google.com!i2no7260852qav.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 26 Nov 2013 10:54:37 -0800 (PST) In-Reply-To: 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> <78030be6-8fe4-4514-85fc-a2627507628f@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Is there some way of calling a system command? From: tolkamp Injection-Date: Tue, 26 Nov 2013 18:54:38 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:17794 Date: 2013-11-26T10:54:37-08:00 List-Id: Op dinsdag 26 november 2013 17:10:32 UTC+1 schreef adambe...@gmail.com: > On Tuesday, November 26, 2013 7:35:26 AM UTC-8, tolkamp wrote: >=20 > > Op zondag 11 juni 2006 15:19:12 UTC+2 schreef jimmaure...@worldnet.att.= net: >=20 >=20 >=20 > > > The easiest way is to simply call the C system command. >=20 > > > The example below was run on my Windows XP system. >=20 > >=20 >=20 > > > with Interfaces.C.Strings; >=20 > > > use Interfaces.C.Strings; >=20 > >=20 >=20 > > > procedure System_Example is >=20 > > > function System_Call(Command : Chars_Ptr) return Interfaces.C.Int; >=20 > > > pragma Import(Convention =3D> C, Entity =3D> System_Call, >=20 > > > External_Name =3D> "system"); >=20 > > > Rc : Interfaces.C.Int; >=20 > >=20 >=20 > > > begin >=20 > > > Rc :=3D System_Call(New_String("dir")); >=20 > > > end System_Example; >=20 >=20 >=20 > > > The important part of the example is the creation of a function >=20 > > > specification I have named System_Call. That function specification >=20 > > > take a parameter of Chars_Ptr, which corresponds to a C char *. >=20 > > > The function specification is used as the Ada interface to the C >=20 > > > system call. The compiler is notified of that association through=20 >=20 > > > the pragma Import. That pragma causes the compiler to link the C >=20 > > > system command and call it whenever System_Call is called in the >=20 > > > Ada code. >=20 >=20 >=20 > > Thank you for your reaction. >=20 > > For me this is not very understandable. >=20 > > Where must I put the directory path to the executable? >=20 > > Is this "dir" in Rc :=3D System_Call(New_String("dir"));? >=20 >=20 >=20 > No, "dir" is the command. The effect of this statement is that it will e= xecute the "dir" command just as if a user had typed it into the Command Pr= ompt window. On Windows, "dir" causes a directory listing to appear on the= screen. >=20 >=20 >=20 > System_Call (that is, the C system() routine) more or less requires a str= ing that is something the user would type in a shell or a Command Prompt wi= ndow. So if you want to include the directory path, just include it as par= t of the command, same as you would if you typed it in yourself: >=20 >=20 >=20 > Rc :=3D System_Call(New_String("c:\users\abc\subdirectory\mytool")); >=20 >=20 >=20 > or use the Ada.Directories and possibly Ada.Directories.Hierarchical_File= _Names to create the file name: >=20 >=20 >=20 > Dir : constant String :=3D "c:\users\abc\subdirectory"; >=20 > =20 >=20 > Rc :=3D System.Call(New_String(Ada.Directories.Compose(Dir, "mytool"))= ); >=20 >=20 >=20 > -- Adam Thank you for your explanation. Now it works, the extra program is started.= =20 The only disadvantage is that the Ada code below the procedure System_Examp= le is suspended untill the extra started program is terminated. Is there a = possibility that the Ada program continues while the extra program runs?