Board index » delphi » command line input

command line input

Is there a way in a pascal program to accept command line input, in the same
command as the program name itself??
eg. like a DOS 'dir /s' -- the '/s' part??
thanks,
            Jon

 

Re:command line input


-- never mind - i figured it out myself.... thanks anyhow!!!

Jon

Quote
Jon's Mail wrote in message <357c316...@news.essex1.com>...
>Is there a way in a pascal program to accept command line input, in the
same
>command as the program name itself??
>eg. like a DOS 'dir /s' -- the '/s' part??
>thanks,
>            Jon

Re:command line input


How? I'd like to know also :)

Quote
Jon's Mail wrote:

> -- never mind - i figured it out myself.... thanks anyhow!!!

> Jon

> Jon's Mail wrote in message <357c316...@news.essex1.com>...
> >Is there a way in a pascal program to accept command line input, in the
> same
> >command as the program name itself??
> >eg. like a DOS 'dir /s' -- the '/s' part??
> >thanks,
> >            Jon

Re:command line input


Tucker schrieb:

Quote

> How? I'd like to know also :)

> > >Is there a way in a pascal program to accept command line input, in the
> > same
> > >command as the program name itself??
> > >eg. like a DOS 'dir /s' -- the '/s' part??
> > >thanks,
> > >            Jon

Look in the help file for ParamCount and ParamStr(n).

And:
In PSPseg:$0080 there is a string[127] containing the whole
parameter list at once. This is inherited from good old CP/M,
and older, from the Intellec computer.

Also look in your help file for GetEnv('PATH');

Visit:
http://www.geocities.com/SiliconValley/2926/tp.html

Franz Glaser

Re:command line input


Please do not (cross)post to the obsolete comp.lang.pascal.

Quote
In article <357c316...@news.essex1.com>, Jon's Mail <jwads...@yahoo.com> wrote:

:Is there a way in a pascal program to accept command line input, in the same
:command as the program name itself??
:eg. like a DOS 'dir /s' -- the '/s' part??

Besides the obvious ParamStr and ParamCount (please see your Turbo
Pascal manual for the basics) there is this information

 143222 May 26 1998 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked

-Subject: Capturing the entire command line

18. *****
 Q: How can I obtain the entire command line (spaces and all)?

 A: ParamCount and ParamStr are for parsed parts of the command line
and cannot be used to get the command line exactly as it was. See
what happens if you try to capture
  "Hello.   I'm here"
you'll end up with a false number of blanks. For obtaining the
command line unaltered use
  type CommandLineType = string[127];
  var  CommandLinePtr  : ^CommandLineType;
  begin
    CommandLinePtr := Ptr(PrefixSeg, $80);
    writeln (CommandLinePtr^);
  end;
A warning. If you want to get this correct (the same goes for TP's
own ParamStr and ParamCount) apply them early in your program. At
least they must be used before any disk I/O takes place!
:
A related example demonstrating a function giving the number of
characters on the command line
  function CMDNBRFN : byte;
  var paramPtr : ^byte;
  begin
    paramPtr := Ptr (PrefixSeg, $80);
    cmdnbrfn := paramPtr^
  end;  (* cmdnbrfn *)
For the contents of the Program Segment Prefix (PSP) see Tischer,
Michael (1992), PC Intern System Programming, p. 753.
--------------------------------------------------------------------

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

Re:command line input


In article <6li63i$...@majakka.uwasa.fi>,

Quote
Timo Salmi <t...@majakka.uwasa.fi> wrote:
>A warning. If you want to get this correct (the same goes for TP's
>own ParamStr and ParamCount) apply them early in your program. At
>least they must be used before any disk I/O takes place!

That is misinformation. There is no need to use paramount and paramstr
only before disk IO is done. TP is a HLL, not an assembler.

Osmo

Re:command line input


Quote
> That is misinformation. There is no need to use paramount and paramstr
> only before disk IO is done. TP is a HLL, not an assembler.

Old TP versions used FCB style file I/O, overwriting the command line
parameters at a file open, and overwriting the other FCB at a second
file open... This was a very bad idea of DOS 1.0!

Andras

Re:command line input


Quote
Timo Salmi wrote in message <6li63i$...@majakka.uwasa.fi>...
> A: ParamCount and ParamStr are for parsed parts of the command line
>and cannot be used to get the command line exactly as it was.
[snip]
>A warning. If you want to get this correct (the same goes for TP's
>own ParamStr and ParamCount) apply them early in your program. At
>least they must be used before any disk I/O takes place!

Surely not - try it! I thought we'd discussed this recently? I
mentioned that the memory used (PrefixSeg:$80) was a default DTA in
ancient times so maybe this was a problem in a *really* old version of
TP, but R.E.Donais tried it on TP versions 1..7 and found no problem.
So presumably TP either changed the default DTA address or saved the
parameters during initialisation. It has been pointed out that
programmers can corrupt command line parameters (ParamStr(1) and
higher, anyway - ParamStr(0) is harder to corrupt) but R.E.Donais
wrote in message <3580883b.81388...@news.southeast.net>...

Quote

>As I said before, if you are making your own system calls, performing
>your own low-level file i/o, using inline statements or external
>routines then this might be a valid concern.  But everything that I
>have tried indicates that the command line is not affected by any
>_standard_ TP statement.  This applies to COM files produced by TP
>CP/M-80 and MS/DOS versions 1.0, 2.0 and 3.0.

If anyone can produce a program which illustrates a problem with
ParamStr use after disk I/O I would love to see it and I'm sure many
others would too.

FP

Re:command line input


Quote
In article <6ljjov$4a...@news.indigo.ie>, Frank Peelo <fpe...@indigo.ie> wrote:
:Timo Salmi wrote in message <6li63i$...@majakka.uwasa.fi>...

:> A: ParamCount and ParamStr are for parsed parts of the command line
:>and cannot be used to get the command line exactly as it was.
:[snip]
:>A warning. If you want to get this correct (the same goes for TP's
:>own ParamStr and ParamCount) apply them early in your program. At
:>least they must be used before any disk I/O takes place!
:
:Surely not - try it! I thought we'd discussed this recently? I

Easy, Dear Frank, easy. :-) :-) That's what's currently in the FAQ.
If (and no doubt when) it now turns out that the warning is
unnecessary, I'll remove it. Note, however, that nothing will be
lost by storing the values early in the program. Remember, we
discussed that, too :-).

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

Re:command line input


Hello,

    You can use 'paramstr'.

Timomai

Jon's Mail a crit:

Quote
> Is there a way in a pascal program to accept command line input, in the same
> command as the program name itself??
> eg. like a DOS 'dir /s' -- the '/s' part??
> thanks,
>             Jon

Re:command line input


Franck Doray a crit:

Quote
> Hello,

>     You can use 'paramstr'.

> Timomai

I forgot :
   you should use paramcount to know how many parameters you have.
and to get the first one you have to write : paramstr(1). And paramstr(0) gives
you the name of your program which is running.
Quote

> Jon's Mail a crit:

> > Is there a way in a pascal program to accept command line input, in the same
> > command as the program name itself??
> > eg. like a DOS 'dir /s' -- the '/s' part??
> > thanks,
> >             Jon

Other Threads