comp.lang.ada
 help / color / mirror / Atom feed
From: tolkamp <f.tolkamp@gmail.com>
Subject: Re: Is there some way of calling a system command?
Date: Tue, 26 Nov 2013 10:54:37 -0800 (PST)
Date: 2013-11-26T10:54:37-08:00	[thread overview]
Message-ID: <bc56b9df-1fdb-41e6-9990-cbac7499f873@googlegroups.com> (raw)
In-Reply-To: <a5e15b23-48bd-4408-87d8-51ddbe29bdd6@googlegroups.com>

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:
> 
> > Op zondag 11 juni 2006 15:19:12 UTC+2 schreef jimmaure...@worldnet.att.net:
> 
> 
> 
> > > 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.
> 
> 
> 
> > 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"));?
> 
> 
> 
> No, "dir" is the command.  The effect of this statement is that it will execute the "dir" command just as if a user had typed it into the Command Prompt window.  On Windows, "dir" causes a directory listing to appear on the screen.
> 
> 
> 
> System_Call (that is, the C system() routine) more or less requires a string that is something the user would type in a shell or a Command Prompt window.  So if you want to include the directory path, just include it as part of the command, same as you would if you typed it in yourself:
> 
> 
> 
>    Rc := System_Call(New_String("c:\users\abc\subdirectory\mytool"));
> 
> 
> 
> or use the Ada.Directories and possibly Ada.Directories.Hierarchical_File_Names to create the file name:
> 
> 
> 
>    Dir : constant String := "c:\users\abc\subdirectory";
> 
>    
> 
>    Rc := System.Call(New_String(Ada.Directories.Compose(Dir, "mytool")));
> 
> 
> 
>                                    -- Adam

Thank you for your explanation. Now it works, the extra program is started. 
The only disadvantage is that the Ada code below the procedure System_Example is suspended untill the extra started program is terminated. Is there a possibility that the Ada program continues while the extra program runs?

  reply	other threads:[~2013-11-26 18:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-11  8:46 Is there some way of calling a system command? Aldebaran
2006-06-11 13:19 ` jimmaureenrogers
2006-06-11 14:35   ` Aldebaran
2006-06-15 14:03   ` Michel Simeon
2006-06-15 14:11     ` Ludovic Brenta
2006-06-15 14:57       ` Michel Simeon
2013-11-26 15:35   ` tolkamp
2013-11-26 16:10     ` adambeneschan
2013-11-26 18:54       ` tolkamp [this message]
2013-11-26 19:49         ` adambeneschan
2013-11-26 21:03           ` Dirk Heinrichs
2013-11-27  7:02           ` Georg Bauhaus
2013-11-27 14:10             ` Eryndlia Mavourneen
2013-11-27  8:52           ` Jacob Sparre Andersen
2013-11-27 18:56           ` tolkamp
2013-11-26 18:24     ` Per Sandberg
2013-11-26 18:58       ` Jeffrey Carter
2013-11-26 20:31         ` Dmitry A. Kazakov
2013-11-26 22:52           ` Randy Brukardt
2013-11-28  5:37         ` Per Sandberg
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox