Link to home
Start Free TrialLog in
Avatar of Dooglave
Dooglave

asked on

Set Variable use variable in batch

See my script to set the location is broken.  Help me fix it.


My Batch log:
__________________________________________________________________________________________________________
C:\>reinstall_integrity.cmd

C:\>for /F %F in ('dir/s/b c:\iflex_clientHFA6.exe') do set location=%F

C:\>set location=c:\Documents

C:\>ECHO !location!
!location!

C:\>start /D !location! iflex_clientHFA6.exe /s /v /qn RESETCONFIG=YES
The system cannot find the file iflex_clientHFA6.exe.

C:\>tasklist.exe /FI "IMAGENAME eq iflex_clientHFA6.exe"   2>NUL  | find.exe "if
lex_clientHFA6.exe"   1>NUL  && GOTO taskcheck

C:\>goto end

C:\>ECHO Integrity Flex has finished installing. Please save any work, close all
 programs, then reboot your computer.
Integrity Flex has finished installing. Please save any work, close all programs
, then reboot your computer.

C:\>dir/s/b c:\iflex_clientHFA6.exe
c:\Documents and Settings\dougrich\Desktop\iflex_clientHFA6.exe
__________________________________________________________________________________________________________



Current Batch file:
__________________________________________________________________________________________________________
for /f %%F in ('dir/s/b c:\iflex_clientHFA6.exe') do set location=%%F
ECHO !location!
start /D !location! iflex_clientHFA6.exe /s /v /qn RESETCONFIG=YES


tasklist.exe /FI "IMAGENAME eq iflex_clientHFA6.exe" 2>NUL | find.exe "iflex_clientHFA6.exe" >NUL && GOTO taskcheck
goto end

:taskcheck
  ECHO Integrity Flex is installing. Please Wait . .. ...
  ping.exe -n 6 -w 1000 127.0.0.1 >NUL
  tasklist.exe /FI "IMAGENAME eq iflex_clientHFA6.exe" 2>NUL | find.exe "iflex_clientHFA6.exe" >NUL && GOTO taskcheck
  goto end

:end
  ECHO Integrity Flex has finished installing. Please save any work, close all programs, then reboot your computer.
__________________________________________________________________________________________________________
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of knightEknight
Also, if the folder name has spaces in it, you need to quote it:

  start /D "!location!" iflex_clientHFA6.exe /s /v /qn RESETCONFIG=YES

Or:

  start /D "%location%" iflex_clientHFA6.exe /s /v /qn RESETCONFIG=YES

Also, it appears that you are duplicating the program filename as a parameter:

  start /D "%location%" iflex_clientHFA6.exe /s /v /qn RESETCONFIG=YES

The location variable will contain the drive, path, and filename, so there is no need to include it:

  start /D "%location%"  /s /v /qn RESETCONFIG=YES


OOPS!  I see now, that is what Start /D is for -- never mind my last.
Avatar of Dooglave
Dooglave

ASKER

Yeah all that stuff has been tested and works fine.   What I need to get past is this

C:\>for /F %F in ('dir/s/b c:\iflex_clientHFA6.exe') do set location=%F

C:\>set location=c:\Documents

 c:\Documents should be c:\Documents and Settings\username\Desktop

So it's this line that's broke: for /f %%F in ('dir/s/b c:\iflex_clientHFA6.exe') do set location=%%F

I tried "%%F" but no change.
Also want to confim that I set
SETLOCAL ENABLEDELAYEDEXPANSION

no change
Woo hoo!   I got it to work:

Here is the code:
********************************************************
SETLOCAL ENABLEDELAYEDEXPANSION

for /f "tokens=* delims= " %%a in ('dir/s/b/a-s c:\iflex_clientHFA6.exe') do set location=%%~DPa
ECHO %location%
start /D "%location%" iflex_clientHFA6.exe /s /v /qn RESETCONFIG=YES


tasklist.exe /FI "IMAGENAME eq iflex_clientHFA6.exe" 2>NUL | find.exe "iflex_clientHFA6.exe" >NUL && GOTO taskcheck
goto end

:taskcheck
  ECHO Integrity Flex is installing. Please Wait . .. ...
  ping.exe -n 6 -w 1000 127.0.0.1 >NUL
  tasklist.exe /FI "IMAGENAME eq iflex_clientHFA6.exe" 2>NUL | find.exe "iflex_clientHFA6.exe" >NUL && GOTO taskcheck
  goto end

:end
  ECHO Integrity Flex has finished installing. Please save any work, close all programs, then reboot your computer.
********************************************************
Except now I'm getting an "Open File - Security Warning" that I wasn't getting before.   hmmm