Getting Startup Path of the running programm

Started by ORGA-SOFT B., September 14, 2017, 02:42:48 PM

Previous topic - Next topic

ORGA-SOFT B.

Hello,

i'm looking for a function that returns the startup Path of the programm.

For example i run the following comamnd fglrun /mypath/myApp/bin/startmenu.42r
In my Genero app i have to find out in which  path the 42r file is located.

is there a function that returns this path?

os.path.pwd returns the path were i stand when i run the command above

Laurent G.

Hello,

Maybe using on arg_val(0) could help:

bash-3.2$ cat GSPRP.4gl
Import os

main

  define GeneroVMArgument, StartupPath String
 
  let GeneroVMArgument = arg_val(0)
  let StartupPath = os.path.dirName(GeneroVMArgument)

  display "Startup Path of the current Running Program : " || StartupPath

end main

bash-3.2$ fglrun /Users/laurent/Desktop/TMP/GettingStartupPathRunningProgram/GSPRP.42r
Startup Path of the current Running Program : /Users/laurent/Desktop/TMP/GettingStartupPathRunningProgram

Best

Laurent

Laurent G.

I meant using os.path.dirName on arg_val(0) sorry

Quote from: Laurent G. on September 14, 2017, 07:18:27 PM
Hello,

Maybe using on arg_val(0) could help:

bash-3.2$ cat GSPRP.4gl
Import os

main

  define GeneroVMArgument, StartupPath String
 
  let GeneroVMArgument = arg_val(0)
  let StartupPath = os.path.dirName(GeneroVMArgument)

  display "Startup Path of the current Running Program : " || StartupPath

end main

bash-3.2$ fglrun /Users/laurent/Desktop/TMP/GettingStartupPathRunningProgram/GSPRP.42r
Startup Path of the current Running Program : /Users/laurent/Desktop/TMP/GettingStartupPathRunningProgram

Best

Laurent

ORGA-SOFT B.

Good Morning Laurent,

that's what i'm looking for.

So complete i have to figure out the absolute path.

let GeneroVMArgument = arg_val(0)
let StartupPath = os.path.dirName(GeneroVMArgument)
let StartupPath = os.path.fullPath(StartupPath)

with this additional line in all cases the startuppath is correct.

Many Thanks for your great support.

Martin Stigmond

Laurent G.

You are very welcome Martin,

I didn't have to use the extra os.path.fullPath(StartupPath) on my MacOs laptop, I'm glad this is working for you in all cases you need it.

Also and to be complete, my colleague Florencia pointed me to an even more efficient way to achieve what you want (in one line only, how could I miss that!)

let StartupPath = base.Application.getProgramDir()

Best

Laurent