CDSoft / pp

PP - Generic preprocessor (with pandoc in mind) - macros, literate programming, diagrams, scripts...

Home Page:http://cdelord.fr/pp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`!env(VARNAME)` Fails under Windows

tajmone opened this issue · comments

I've tried all sorts of combinations, but I can't get !env() working (Win10 x64).

None of these worked:

!env(PATH)
!env(%PATH%)
!env(%%PATH%%)
!env($PATH)
!env($PATH$)

If I understood correctly, it should allow access to env vars of the current session (eg: within the CMD):

!env(VARNAME)
pp preprocesses and emits the value of the process environment variable VARNAME.

It would be really nice to have this feature working under Windows.

ERRATA: it seems that the problem was due to letter casing, in fact this works:

!env(Path)

Which is rather unexpected since you'll commonly find DOS/CMD examples on MS docs using PATH in uppercase. Also, the fact that it has to be written exactly with first capital letter makes it troublesome to remember in an environment that promotes case-insensitivity!

I've done some more tests with custom env-vars which I defined in CMD. For example, if inside CMD I define some var:

SET "myvar=Some Var"

then I can access it via PP with:

!env(myvar)

but not with:

!env(MYVAR)
!env(MyVar)

... which confirms that PP is case-sensitive --- even though Windows isn't, in fact I can print the var from the CMD with all of these:

ECHO %myvar%
ECHO %MYVAR%
ECHO %MyVar%

Why case-sensitivity creeps in? I guess under Linux casing is an issue and this would be the expected behavior; but on Windows it is rather unexpected.

Maybe a note in the documentation could be added for Win users about variables having to be correctly letter-cased.

Feature Request

Better still, could it be possible to have the Window version of PP ignore variables case? Chances are that in a workflow of chained scripts under Windows no sanitation of var-names casing will be in place.

As for sytem-defined env-vars, that is a bit of a nightmare because Windows is rather arbitrary about its usage of letter casing. This is a (cut-down) dump of the output from SET command:

ALLUSERSPROFILE=C:\ProgramData
ChocolateyInstall=C:\ProgramData\chocolatey
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
EMAIL=D:\PostOffice\MailBoxes
FPPUILang=en-US
PROCESSOR_ARCHITECTURE=AMD64
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
SystemDrive=C:
SystemRoot=C:\WINDOWS
windir=C:\WINDOWS
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log

Windows sets some sys-envs all in uppercase, some all in lowercase, and others in mixed-case. A bit of a nightmare to follow this (lack) of criteria, so if !env() would be case-insensitive it would make things easier.

I was not aware of this difference between Linux and Windows. It seems to be good idea to make env case-insensitive, on Windows only. I'll fix it.

It's fixed. I have no regression on Linux. Could you please test it on Windows?

Hi @CDSoft !

Yes, I've tested it an confirm that now it works case-insensitevely.

The following now all produce valid output of PATH env-var:

!env(path)
!env(PATH)
!env(Path)

Thanks a lot, this definitely improves work on Windows!