[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Env["PWD"], why not?



On 4/19/25 04:54, gbWilly wrote:

On Saturday, April 19th, 2025 at 12:07, Bruce Steers bsteers4@xxxxxxxxx wrote:

    a hack? dang the other day it was an undocumented feature :(
    Seemed to me like a handy feature.
    Oh well. Thanks for the reply.

    I could "hack" Shell easy enough by adding "cd " & Shell(sDir) &
    "; " to the start of the command string but how could i hack Exec
    as it's only single commands?

    Respects
    BruceS


You can hack the single command part of Exec by adding System.Shell as first item, "-c" as second and the full command string as third. Here is an example of some code of mine I use to make code created scripts executable.

sCommand = Subst("chmod u+x &1", $sLoadedFile)
Wait 0.01
Exec [System.Shell, "-c", sCommand] Wait


gbWilly

A Note:

Some cli functions use the env variable PWD others use the process cwd
current working directory. You should attempts to keep both in sync.

Linux process table contains an inode reference to the current working
directory. The shell normally  keeps this in sync with the PWD environment
variable.

This may help calls to be more reliable

'Try this in your app: to sync where the os thinks you are and where cli commands think you are

Extern chdir(Dest As String) As Integer In "libc:6"
Try chdir(Env["PWD"])              ' but be aware to change back after you are done

You can also find out where that is by using
Extern getcwd(buf As Pointer, size As Integer) As String In "libc:6"
Dim dirbuf As Pointer = Alloc(2048)

Print "start at ";; getcwd(dirbuf, 2048)


--

~~~~ Brian

Attachment: OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


References:
Env["PWD"], why not?Bruce Steers <bsteers4@xxxxxxxxx>
Re: Env["PWD"], why not?Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: Env["PWD"], why not?Bruce Steers <bsteers4@xxxxxxxxx>
Re: Env["PWD"], why not?gbWilly <gbWilly@xxxxxxxxxxxxxx>