Current Working Directory

I just want to verify that in console applications there is no way to get the current working directory. If you use getcwd, it just gives you the virtual Data directory. You can get the directory of the exe itself, but that is it. Is that correct?

It’s not possible directly but there is a workaround.
In the PHP.INI section in ExeOutput, add this line to the end of your PHP.INI:

exepath="%EXOPHPEXEPATH%"

Then, with PHP, you can read this entry:

$valeur = ini_get("exepath");
echo $valeur;
1 Like

I’m not sure if I’m doing this right, because after I added the
exepath="%EXOPHPEXEPATH%"
line to the bottom of the PHP.INI, the value returned by
ini_get("exepath")
is always an empty string. I was hoping to get the full path of the directory i was in when I launch the exe.
I know I can use:
exo_getglobalvariable('HEPublicationPath', '');
but those two aren’t always the same thing.

We finally found a way to make it work, but it’s somewhat specific because PHP doesn’t accept just any directive in its PHP.ini file; you need to use an existing directive.

Here, we chose:

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; https://php.net/upload-tmp-dir            
upload_tmp_dir = "%EXOPHPEXEPATH%"                  

In this case, your PHP code at the beginning must read the value and reset upload_tmp_dir to empty if you use it in your code. Otherwise, leave it as it is.

<?php         

$value = ini_get('upload_tmp_dir');
echo "exepath: $value";  
ini_set('upload_tmp_dir', '');
?>

New environment variable available for console apps in ExeOutput 2024.2:

print ("EXE directory:\n");
$exoexepath = getenv('EXOPHPEXEPATH');
print($exoexepath)

It will return the directory of the exe itself.