home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,182 of 68,980   
   npocmaka to All   
   Re: Side effect of SETLOCAL   
   13 Apr 18 07:47:02   
   
   From: npocmaka@gmail.com   
      
   On Friday, April 13, 2018 at 3:36:22 PM UTC+1, JJ wrote:   
   > On Thu, 12 Apr 2018 09:41:28 -0700 (PDT), npocmaka wrote:   
   >    
   > > On Thursday, April 12, 2018 at 4:52:46 PM UTC+1, JJ wrote:   
   > >> On Thu, 12 Apr 2018 09:20:37 +0200, Herbert Kleebauer wrote:   
   > >>> On 12.04.2018 01:19, Paul Emmons wrote:   
   > >>>> Consider this short demonstration batch file (running under Windows   
   > >>>> 7):   
   > >>>> ______________________________________   
   > >>>> setlocal   
   > >>>> Z:   
   > >>>> cd \TEMP   
   > >>>> dir   
   > >>>> ______________________________________   
   > >>>>    
   > >>>> The dir command lists the files of Z:\temp, proving that this is   
   > >>>> indeed the current directory of Z: at the time.   
   > >>>>    
   > >>>> However, after termination, the current directory of Z: reverts   
   > >>>> to whatever it was before execution.  Furthermore, if before   
   > >>>> execution the current drive and directory per the command prompt   
   > >>>> are for another drive, e.g. C:\, this situation is also restored.   
   > >>>    
   > >>> Isn't this the only purpose of setlocal?   
   > >>>    
   > >>> setlocal /?   
   > >>>    
   > >>> Begins localization of environment changes in a batch file.  Environment   
   > >>> changes made after SETLOCAL has been issued are local to the batch file.   
   > >>> ENDLOCAL must be issued to restore the previous settings.  When the end   
   > >>> of a batch script is reached, an implied ENDLOCAL is executed for any   
   > >>> outstanding SETLOCAL commands issued by that batch script.   
   > >>    
   > >> I'm aware that SETLOCAL does affect the working directory, but I concur   
   with   
   > >> Paul Emmons.   
   > >>    
   > >> SETLOCAL's help only mention "environment". For those who are new to CMD,   
   > >> would think that it means the environment variables. For those who are   
   > >> already familiar with CMD, may have already know this and the   
   "environment"   
   > >> in that context, means the command prompt (or terminal) environment.   
   > >>    
   > >> However, this is not true (at least on Windows 7 version of CMD). SETLOCAL   
   > >> does not affect the states of: ECHO, DPATH, VERIFY, color, and title of   
   the   
   > >> console window. So IMO, SETLOCAL's help is not being clear enough.   
   > >    
   > > DPATH and PATH are affected.KEYS is not.MODE is not.   
   >    
   > MODE is not even an internal command.   
   > But it doesn't really matter.   
   > The point is that SETLOCAL's help is not being clear.   
      
   I think it is. It restores only the command states that are relying on   
   variables - by restoring the variables. In the case of the directory i think   
   it is the %__CD__% variable which cannot be changed directly by the user - but   
   looks like ENDLOCAL has no    
   restrictions over it.(%CD% can be overwritten by the user but it does not   
   change the current directory)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca