Board index » delphi » "commandline" parameters myprogram.exe -hello

"commandline" parameters myprogram.exe -hello

Hello

How do you take arguments to the TP-program from the DOS command line?
Like:     C:\>myprogram /me        or   C:\>myprogram
-takenoprisoners    :)
(myprogram is an exefile)
Is this a part of standardpascal?

/Tobias

 

Re:"commandline" parameters myprogram.exe -hello


Quote
Tobias Andersson <Tobias.Anders...@mbox3.swipnet.se> wrote:
>How do you take arguments to the TP-program from the DOS command line?
>Like:     C:\>myprogram /me        or   C:\>myprogram
>-takenoprisoners    :)
>(myprogram is an exefile)
>Is this a part of standardpascal?

There is (AFAIK) no ANSI Pascal method of fetching command line
arguments.

In Turbo Pascal, however, the number of command line arguments may be
obtained from the ParamCount function:

        function        ParamCount: Word;

and the parameters themselves may be obtained from the ParamStr
function:

        function ParamStr(Index): String;

The 0th parameter under DOS v3.3 or greater is the complete path and
filename of the running executable.

Example:

var i: Word;

begin
     Writeln('There were ', ParamCount+1, ' command line parameters.');
     Writeln;

     for i := 0 to ParamCount do
         Writeln('Parameter ', i, ': "', ParamStr(i), '"')
end.

--
Robert B. Clark
Visit ClarkWehyr Enterprises On-Line at http://www.iquest.net/~rclark/ClarkWehyr.html

[My e-mail address has been ROT-13'ed in order to combat spambots.]

Re:"commandline" parameters myprogram.exe -hello


  Tobias Andersson <Tobias.Anders...@mbox3.swipnet.se> wrote:
Quote
> Hello

> How do you take arguments to the TP-program from the DOS command line?
> Like:     C:\>myprogram /me        or   C:\>myprogram
> -takenoprisoners    :)
> (myprogram is an exefile)

ParamStr(i)
ParamCount
Quote
> Is this a part of standardpascal?

No

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:"commandline" parameters myprogram.exe -hello


Quote
Syarzhuk Kazachehnka (bamboo7...@hotmail.com) wrote:

: ParamStr(i)
: ParamCount

Or if you want to see the commandline exactly as it was written
with all blanks and such (and if you are using turbo pascal in real mode),
then try

   string(ptr(PrefixSeg,$80)^);

Klaus

Re:"commandline" parameters myprogram.exe -hello


Hi Tobias,

Op 14 September 1998, zo ongeveer rond 23:19, was Tobias Andersson bezig een
berichtje in zijn PC te stampen. Dit werd uiteraard opgemerkt door Rene Bakker,
die me{*word*249} de reply-knop inbeukte.

 TA> Hello

 TA> How do you take arguments to the TP-program from the DOS command line?
 TA> Like:     C:\>myprogram /me        or   C:\>myprogram
 TA> -takenoprisoners    :)
 TA> (myprogram is an exefile)
 TA> Is this a part of standardpascal?

Yes, it is!

There are 2 functions, ParamStr and ParamCount, and help is available in Turbo
Pascal, if you don't have TP, here an example:

=== Cut ===

var I: Word;
begin
 for I := 1 to ParamCount do
   Writeln(ParamStr(I));
end.

=== Cut ===

I hope this is what you need...

 TA> /Tobias

                       See ya later, Tobias

                        Signed,
                            Rene

Fidonet: 2:2802/396
Raptornet: 710:100/0
Wolfnet: 350:101/0
Whizznet: 38:600/0
Klippernet: 215:312/0
Freelink: 21:926/0

e-mail: Rene.Bak...@rapmet.iwg.nl (For normal e-mail)
e-mail: Rene-Bak...@hetnet.nl (for attaches, if you have attaches, note it
e-mail: on Rene.Bak...@rapmet.iwg.nl

... 5 miljoen jaar geleden.....

Other Threads