TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender: "Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Date: Mon, 20 Nov 2000 20:18:44 -0600
Reply-To: Randy Brukardt <[log in to unmask]>
Content-Transfer-Encoding: 7bit
From: Randy Brukardt <[log in to unmask]>
In-Reply-To: <01C0532D.74C3DA00@IGNITOR>
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Parts/Attachments: text/plain (44 lines)
> Does anyone know if it is possible to call dos commands (i.e.
> dir, copy, mkdir, etc) from within a Ada program?

Of course it is possible; I've done it frequently.














Oh, you want to know how?

Well, there isn't any way to do it that uses only standard Ada facilities.

For most the items you mentioned above, it probably is best to code the
operation using a package defined by your compiler. Every compiler supports
a directory package, for instance (we also put one into Claw so that people
wouldn't have to depend on the compilers for this vital functionality).
[I've proposed standardizing such a package for the next version of Ada, but
of course that won't help you for a long time...]

To do what you asked for directly, you just need to spawn the command
processor with a command line of the command you want to execute. Your
compiler ought to have a package to spawn commands. (Note that this can be
tricky on some compilers; the command processor may not be named Command.Com
[as it can be replaced, and it is named Cmd.Exe on Windows NT]; it is best
to grab the name and path from the environment variable for that purpose.

This is the same procedure you need to use to run a batch file from an Ada
program. (Why would you want to run a batch file from an Ada program? One
reason is that you need to do so in order to create an Unininstall program
that cleans up everything [otherwise, you would have to leave it's
executable behind].)

                        Randy.

ATOM RSS1 RSS2