Lua os.getenv does not work in a batch file
environment-variables, lua
Solution
Have the batch file run it from a shell so that you get shell variables:
cmd /c C:\path\to\lua myfile.lua
Problem
I have a little script to read my PATH and store in a file, which I would like to be scheduled to run daily. ``` path = os.getenv("PATH") file_name = "C:\\temp.txt" file = io.open(file_name, "w") file:write(path) file:close() ``` If I run it from command line it works, but when I create batch file (I work on Windows XP) and double click it - the os.getenv("PATH") returns false. The batch file: ``` "C:\Program Files\Lua\5.1\lua" store_path.lua ``` I read in comments to this question that it "is not a process environment variable, it's provided by the shell, so it won't work". And indeed, some other env variables (like username) work fine. The two questions I have are: - Why the shell does not have access to the PATH? I thought it would make a copy of the environment (so only setting env variable would be a problem)? - What would be the best way to read the PATH in such a way that I can add it to a scheduler?