Have made a couple of refinements to my Delphi envget program:
It will now accept a second parameter to specify the destination file (which could include a fully qualified path if required).
I'm a bit hesitant in recommending the use of this second parameter as I don't think the method of adding parameters using ExecAndWait will handle spaces very well (if at all), but it should handle file names without any spaces without problem.
The other refinement is to ensure that the Env.txt file is written to the same directory where the EnvGet.exe resides (in the event that parameter 2 is not specified).
Here is the source of the new version:
Code: Select allprogram EnvGet;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
var
env : string;
envFile : TextFile;
envFileName : string;
begin
env := GetEnvironmentVariable (ParamStr(1)); // get env variable using first command line parameter
if length (ParamStr(2)) > 0 then
envFileName := ParamStr(2) // use param 2 as output file if it exists
else
envFileName := ExtractFilePath(ParamStr(0)) + 'Env.txt'; // write env.txt to thefile path of exe
AssignFile (envFile, envFileName);
ReWrite(envFile);
WriteLn(envFile, env); // write env variable value to output file
CloseFile(envFile);
end.
Compiled version is attached. You are free to use this if you wish (as with all my offerings there is absolutely no obligation but a contribution towards cost of development would be appreciated if you find it useful)