Symbolic links and ProgramFileName()

Linux specific forum
infratec
Always Here
Always Here
Posts: 7584
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Symbolic links and ProgramFileName()

Post by infratec »

Hi together,

I want to call a PB program with different names (symbolic links).
Now I have the problem to figure out the name of the caller.

ProgramFileName() returns always the name of the 'real' program.

Any ideas?

Bernd
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Post by Marlin »

Try this:

Code: Select all

MessageRequester(ProgramFilename(), GetEnvironmentVariable("_"))
infratec
Always Here
Always Here
Posts: 7584
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post by infratec »

Hi Marlin,

yes it works and ... no it works not. :(

Since you ask the shell variable $_ it gives you only information about the last called program from out of the shell..
So, if you call your linked PureBASIC file from inside of a script, you get the name of the script, and not the name of the link of the PureBASIC file.

For me, unfortunately, your trick will not work.

But many thanks, it was a good try.

Bernd
infratec
Always Here
Always Here
Posts: 7584
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post by infratec »

I found a solution, but it is one which I not really like:

When I use 'hard' links it works with ProgramFilename().

But since I want to use the program on one side as a cgi and on the other side as a standalone program, I can not be shure that the web stuff is not on an other partition or harddisk.

So the hard link will not work.

Bernd
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Post by Marlin »

infratec wrote:if you call your linked PureBASIC file from inside of a script, you get the name of the script, and not the name of the link of the PureBASIC file
I just tried to reproduce that, but I could not:

I compiled the above code as "callme.bin".
(puttig all on the Desktop - don't think it should behave differently somewhere else)

Code: Select all

$ ln -s callme.bin call2
Created a script "runcall.sh":

Code: Select all

#!/bin/bash
./call2
./callme.bin

Code: Select all

$ ./runcall.sh
Results:

Code: Select all

./call2

Code: Select all

./callme.bin
And that also works the same way, when I call it from a wrapper script that calls ./runcall.sh.

However, when clicking on the link "call2" on the desktop I get the full path to the final executable.

Yes, ProgramFilename() will return the name of the called hardlink.
You could then create hard links where your executable is located
and create soft links on other filesystems to those hard links.
But beware: if you create your original executable again (with the PB compiler),
the formerly created hard links will still point to the old version of your executable!

Can you give a setup that can be used to reproduce the problem you mentioned :?:
infratec
Always Here
Always Here
Posts: 7584
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post by infratec »

Hi Marlin,

my results are different.
Here my code:

The orignal file is called "NameTest".
Than I created a link "NT2"
Than I created the following "NT3" script:

Code: Select all

#!/bin/sh
./NameTest
./NT2
As result I got 2 times NT3 and not NameTest and NT2.

I use Kubuntu 9.04, but I think the system doesn't matter in this case.

One Moment :!:

That's strange:
I noticed that you use "#!/bin/bash". I used "#!/bin/sh".
When I use "#!/bin/bash" it works :?: :!:

Ok, my /bin/sh is a link to /bin/dash and not to /bin/bash.

Hm, but that's even not nice, so it depends also on the used shell.
So I still think that we need a global PureBASIC solution for this.

Bernd
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Post by Marlin »

infratec wrote:So I still think that we need a global PureBASIC solution for this.
That would certainly be nice (if it could be done).
Post Reply