Archive: Read variable from Batch File after ExecWait


Read variable from Batch File after ExecWait
Hello,

I am having difficulty in determining a software version that is a dependency for a package I am building an installer for. Everything else works right now. Once I can grab the existing version, I plan on using VersionCompare once I can determine the existing version.

The main problem is that the company does not provide a Value for the version in the registry, only a Key. Even then, the key has no Values, and is only called the Major.Minor version, not including the Subverion that I need to test for.

The software is EMC's Navisphere CLI. Here is a batch file I am using to grab the version:

Called from NSIS as:

ExecWait 'getNaviVer.cmd "$navipath"'

getNaviVer.cmd
--

cd %1
for /f "tokens=4" %%i in ('navicli.exe -help ^| findstr "Revision"') do set NaviCLIVersion=%%i
echo Navi Version is [%NaviCLIVersion%]

--

This works, and is the only way I have found to obtain the full version. However, I have not been able to read the variable set by the batch file for use by NSIS. This makes sense since this is a child process setting a variable, which would not stick to the parent.

I tried: "ReadEnvStr $naviver NaviCLIVersion" with no luck

Before I went down the path of looking at xset or some other hack, I wanted to check myself and see if there is an easier way to do this, since I'd prefer not to modify their environment anyway.

Thanks for any assistance.

Vinny


Isn't possible to write %NaviCLIVersion% e.g. in registry and have nsis read it from there?


What a great, and simple work around :)

I would prefer not to write anything to their system, but this would definitely work. In fact, I may write it to the existing Key as a Value, since they don't do it for you ...

Thanks!


You can execute navicli.exe with nsExec::ExecToLog and parse the output with WordFind and friends.


Thanks for this suggestion, I figured out to use nsExec the hard way, but I like what you suggest about parsing a log. I may switch to doing that, but for now I am keeping it under a key in my own software entry. For anyone interested, here is what I ended up doing:

--setNaviVer.cmd--
if [%1]==[] (
cd "c:\program files\emc\navisphere cli"
) else (
cd %1
)
for /f "tokens=4" %%i in ('navicli.exe -help ^| findstr "Revision"') do set NaviCLIVersion=%%i
if defined NaviCLIVersion reg add "HKLM\SOFTWARE\My Company\My Product" /v NaviCLI_Version /d %NaviCLIVersion% /f
--setNaviVer.cmd--

--inside nsis script--
nsExec::Exec 'setNaviVer.cmd "$navipath"'
ReadRegStr $naviVer HKLM "SOFTWARE\My Company\My Product" "NaviCLI_Version"
--inside nsis script--


The reason that your previous way didn't work is because when execwait runs your batch file, any changes to environment variables are not propagated to the parent (the nsis installer) and this is true for all programming languages.

My favorite way out of this is to write batch files that only output the value (nothing else) and use

var /GLOBAL myvalueinhere
nsExec::ExecToStack 'cmd /c mybatch.cmd'
pop $myvalueinhere

and in the batch file make sure that no errors can happen so for example if reg.exe has a problem

re.exe query etc.etc.etc... 2>nul

just in case errors get into the output because I think ExecToStack retrieves both stdout and stderr.

Your way works too :-)