Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-09

Read from command line

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Aviles

Hello all,

In the old TP there just to be a way to read a string from the command line at the same time you invoked the program thus doing:

myprogram param1 param2

made those two variables available to the program and you could do some action, just like passing variables to a function.

How do you do that in FPC in Linux?

Thanks
-pa

Reply by email

DONALD PEDDER
to Paul Aviles: In the old TP there just to be a way to read a string from the command line at the same…
Show quoted text 6 lines
myprogram param1 param2 made those two variables available to the program and you could do some action, just like passing variables to a function. How do you do that in FPC in Linux?

Don't know if it's different in Linux, but in the DOS version at least you can use paramstr(1), paramstr(2), etc.

if (paramstr(1)='test') then writenln('you passed the parameter passing test')

regards,
DONALD.

E-mail -
BIG DON's Home-page - http://jedi.apana.org.au/~jims_son Pedder Passer Rating - http://jedi.apana.org.au/~jims_son/PPR AusNFL mailing-list - http://jedi.apana.org.au/mailman/listinfo/ausnfl

"What I always wanted is to be accepted, not understood" - MAN RAY

Reply by email

James Mills
to DONALD PEDDER
DONALD PEDDER wrote 5 lines
Don't know if it's different in Linux, but in the DOS version at least you can use paramstr(1), paramstr(2), etc. if (paramstr(1)='test') then writenln('you passed the parameter passing test')

It isn't any different on Linux:

paramCount (returns the number of parameters passed to the program) paramStr(i) (returns the i'th parameter)

cheers
James

- -Zero Defect Software Engineers Group - ZDSEG - -You need only two tools. WD-40 and duct tape. -If it doesn't move and it should, use WD-40. -If it moves and shouldn't, use the tape.

Reply by email

Jeff Pohlmeyer

There is a subtle difference between ParamStr(0) and argv[0]:

argv[0] is the verbatim command passed to the shell. ParamStr(0) is the full path to the executable.

Neither of these will dereference a symlink, to do that you can call ReadLink recursively, or ReadLink(/proc/<PID>/exe)

Also note that the argv's are zero-based pchar's,
the paramstr's are one-based pascal strings.

The argv's are also writeable:

 This works:
   argv[0][1]:='x';
 But this doesn't:
   ParamStr(0)[1]:='x';

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com

Reply by email