How to get launched app name in case of symlink lazarus / 66-Unix ---------------------------------------------------------------------- zim · 2024-01-17 12:02 Hi all ! If I run application via symlink, somehow ParamStr(0) returns a physical name - i.e. symlink target, not source Is there any API to get a source name ? ---------------------------------------------------------------------- KodeZwerg · 2024-01-17 13:44 Since you forgot to tell what OS you run your app, here is a possible way: unit LazFileUtils contain GetPhysicalFilename(), feed that with your symbolic link (ParamStr(0)) and it returns the real path/filename ---------------------------------------------------------------------- zim · 2024-01-18 11:42 Quote from: KodeZwerg on January 17, 2024, 02:44:51 pmSince you forgot to tell what OS you run your app, here is a possible way: unit LazFileUtils contain GetPhysicalFilename(), feed that with your symbolic link (ParamStr(0)) and it returns the real path/filename I just thought that "Unix" group should be enough The problem is that ParamStr(0) initially contains the symlink target name, not source, and Argv[0] also does I finally decided to use hardlinks, that is no so good, but at least that works. Possibly that is some Linux internal behaviour. But maybe some API is present to get source name ? ---------------------------------------------------------------------- TRon · 2024-01-18 13:14 Quote from: zim on January 18, 2024, 12:42:40 pmThe problem is that ParamStr(0) initially contains the symlink target name, not source, and Argv[0] also does They are the same and yes they do provide the actual executable (not the symlink). See PascalDragon's (correct) answer, directly below this post. For getting the symlink you can try (baseunix.)fpReadLink on /proc//cwd to get the working directory from which the symlink was executed and then concat the result from reading a line of text from /proc//cmdline Depending from which directory the symlink was started the concatted answer contains a relative path (so you might have to convert it to an absolute path). You can retrieve the pid with (baseunix.)fpGetPid or you could use self. ---------------------------------------------------------------------- PascalDragon · 2024-01-18 20:59 Quote from: zim on January 17, 2024, 01:02:09 pmIf I run application via symlink, somehow ParamStr(0) returns a physical name - i.e. symlink target, not source Is there any API to get a source name ? On *nix you can directly use argv[0] for that (cause ParamStr(0) returns /proc/self/exe). ---------------------------------------------------------------------- TRon · 2024-01-19 03:39 Quote from: PascalDragon on January 18, 2024, 09:59:41 pmOn *nix you can directly use argv[0] for that (cause ParamStr(0) returns /proc/self/exe). Ah, then I am mistaken. I stand corrected. Thank you ! ---------------------------------------------------------------------- zim · 2024-01-23 14:43 Sorry, all that stuff does not help. Either ParamStr(0) or argv[0] contains symlink target name, not source. The problem is I want to share same executable between several tasks located in different folders and care on exact action depending on the folder. But in the said case, even I run executable (symlinked to every specified folder) - every time I get the same app name, not different names ---------------------------------------------------------------------- TRon · 2024-01-23 14:55 Quote from: zim on January 23, 2024, 03:43:22 pmSorry, all that stuff does not help. Either ParamStr(0) or argv[0] contains symlink target name, not source. Oh, that is strange as ti works for me. Which Linux and version of Free Pascal are you using ? Code: [Select]./startupper Example to demonstrate differences between executable invoked from command line a) directly and b) using a symbolic link Running this executable file directly (/media/ramdisk/start/startupper)            argv[0] = /media/ramdisk/start/startupper -- /media/ramdisk/start/startupper        paramstr(0) = /media/ramdisk/start/startupper /proc/self/cmdline = /media/ramdisk/start/startupper INFORM ExpandFileName(argv[0]) = /media/ramdisk/start/startupper --- Running this executable file indirectly using a symbolic link (some_directory/test_symlink)            argv[0] = some_directory/test_symlink -- /media/ramdisk/start/some_directory/test_symlink        paramstr(0) = /media/ramdisk/start/startupper /proc/self/cmdline = some_directory/test_symlink INFORM ExpandFileName(argv[0]) = /media/ramdisk/start/some_directory/test_symlink --- TODO: clean-up the mess and fix expandfilename usage