[Gambas-user] Gambas script gbs Application.Path Args[0]
Bruce Steers
bsteers4 at gmail.com
Sun Nov 1 22:07:29 CET 2020
Thank you For the detailed reply there fella.
In short i want the directory the command was run from.
A normal exe i could use Application.Path or Args[0] to get the folder the
program was launched from
As for a script it cannot load a custom icon i may have in the script
folder as i cannot get it via normal methods.
That's my initial problem.
You mistake me, i do not want the working directory at all, an error in
wording.
I Use application.Path or Args[0] in a few of my programs, some of them can
relaunch as root by adding pkexec to Args[0] and relaunching.
I use application.path to get the absolute path.
Maybe i could take a look at the code and see if there is a way to pass the
args[0] and application.path to the script interpreter?
otherwise both things Args[0] and Application.Path are pretty useless in a
script. and so far, the only real problem i've found with gambas
scripting. I'm kinda digging it otherwise.
Scripting could be an alternative for many things.
Could be an easy to edit app in a folder full of stuff you want to process,
can't have all that stuff in a gambas source folder as it would compile
into the exe so a script would be ideal there.
On Sun, 1 Nov 2020 at 19:47, Tobias Boege <taboege at gmail.com> wrote:
> On Sun, 01 Nov 2020, Bruce Steers wrote:
> > Sorry i meant the directory the script was launched from like Args[0] and
> > Application.Path would produce.
> > I want to access files in the App dir like a gambas executable can.
> >
> > I used the word "working" there by mistake but thank you knowing .Dir
> works
> > as normal is useful :)
> > Cheers
> >
>
> Let me get the terminology of my answer straight: a Gambas project has a
> *project directory* which is where its source code, configuration and data
> files are stored. This can be accessible at runtime through
> Application.Path,
> but keep in mind that a Gambas script is embedded into a temporary project
> on the fly, so you get that project's path instead of the script file path
> (as you already observed), and that Application.Path of an executable will
> be something else (IIRC just /tmp). An executable is not unpacked into the
> filesystem just to be able to point Application.Path to it. Therefore any
> use of Application.Path in non-debugging code should raise at least two
> eyebrows -- chances are you're making your project unpackageable.
>
> Another thing is the current working directory (cwd), which is a familiar
> concept from the shell and other programming languages. The cwd at program
> startup is available through Application.Dir. However, the Gambas language
> does *not* have a concept of "current working directory", in that relative
> paths in your code are *always* interpreted by Gambas built-ins as relative
> to the project directory, never to the environment's cwd. In case you're
> running from an executable archive, Gambas will transparently access the
> files in the memory-mapped archive structure and give you their contents.
>
> You seem to want to use paths relative to Application.Dir. That property
> should contain the right cwd no matter how you run the Gambas program --
> from a project, script or executable. But maybe you're using it wrong?
> I can't tell without seeing your code. Keep in mind that relative paths
> in your Gambas program do *not* do what you're used to from the shell!
>
> In short:
>
> - Don't refer to Application.Path for project data, use relative
> paths instead.
>
> - Don't use relative paths for files in the cwd, make them absolute
> paths with Application.Dir &/ ...
>
> Regards,
> Tobias
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201101/966e912f/attachment.htm>
More information about the User
mailing list