windows - How can I run a batch file which gets drive space and keeps CMD open? -


i'm running batch file

/k  cd c:\  /f "tokens=1-3" %a in ('wmic logicaldisk freespace^,name^,size ^|findstr /i /v "name"') @echo wsh.echo "%b" ^& " free=" ^& formatnumber^(cdbl^(%a^)/1024/1024/1024, 2^)^& " gib"^& " size=" ^& formatnumber^(cdbl^(%c^)/1024/1024/1024, 2^)^& " gib" > %temp%\tmp.vbs & @if not "%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs & del %temp%\tmp.vbs  pause 

when run loop in cmd on own, works fine. when attempt run in batch file closes cmd before can information. fails change directory c:\, once loop added batch file. need pre-fix loop cmd knows how handle it?

you should batch file :

when ran batch file should add sign percent % variable escape %a must %%a , son on ...

@echo off /f "tokens=1-3" %%a in ('wmic logicaldisk freespace^,name^,size ^|findstr /i /v "name"') @echo wsh.echo "%%b" ^& " free=" ^& formatnumber^(cdbl^(%%a^)/1024/1024/1024, 2^)^& " gib"^& " size=" ^& formatnumber^(cdbl^(%%c^)/1024/1024/1024, 2^)^& " gib" > %temp%\tmp.vbs & @if not "%%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs & del %temp%\tmp.vbs pause 

Comments