Sign in Join

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

Mailing lists / fpc-pascal / 2006-04

ParamStr(0) bug??

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Bob Richards

I have written a program who's behavior depends on the name by which it has been invoked. This is not uncommon, for instance sendmail invoked as mailq behaves in a completely different way.

Anyway, it all works as intended as long as I *copy* the executable to a different name. However, if I use a symlink, the ParamStr(0) function doesn't work as I would expect. It always returns the name of the executable not the name of the link to it.

Example:

Program test;
Begin
  WriteLn('This program was executed as: ',ParamStr(0));
end.

----

$ ./test
This program was executed as: /home/bob/pascal/test/test

cp test test1
./test1
This program was executed as: /home/bob/pascal/test/test1 $

$ ln -s test test1
$ ./test1
This program was executed as: /home/bob/pascal/test/test
$

-----

Is there a way to make this work properly? Another method? Is this a bug?

Bob

PGP Encrypted E-Mail Prefered Public Key at: http://www.tamara-b.org/~bob/pubkey.asc .
John Coppens
to Bob Richards
I have written a program who's behavior depends on the name by which it has been invoked. This is not uncommon, for instance sendmail invoked as mailq behaves in a completely different way.

You could try to access the environment variables - the '_' variable contains the command used to start the program. Just tested it - it shows the link.

John