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,046 of 68,980   
   JJ to John Gray   
   Re: In second batch file, find the name    
   07 Sep 17 17:43:18   
   
   From: jj4public@vfemail.net   
      
   On Thu, 7 Sep 2017 00:35:27 -0700 (PDT), John Gray wrote:   
   > In a called batch file, I would like to determine the name (as in %~n0) of   
   > the batch file which called itme, but without passing this name as a   
   > parameter.   
   > Is this possible?   
   > In second batch file,   
   > I've done some searching in this group but can only find the suggestion to   
   give the name of the calling batch file as a parameter.   
   >   
   > Trivial example:   
   >   
   >:: Caller.bat   
   > call called.bat   
   > exit /b   
   >   
   >:: Called.bat   
   >:: some code to find the name of the calling batch file   
   > echo Called.bat was called by %name-of-caller%   
   > goto :eof   
      
   If without passing some information as a batch file parameter is your only   
   requirement, then you can use either environment variable or a file instead.   
   e.g.   
      
     ::Caller.bat   
     ::using environment variable   
     set caller=%~n0   
     call called.bat   
     goto :eof   
      
     ::Called.bat   
     ::using environment variable   
     echo Called.bat was called by %caller%   
     goto :eof   
      
     ::Caller.bat   
     ::using file   
     >"%temp%\caller.tmp" echo %~n0   
     call called.bat   
     goto :eof   
      
     ::Called.bat   
     ::using file   
     for /f "delims=" %%A in (%temp%\caller.tmp) do (   
       echo Called.bat was called by %%A   
     )   
     goto :eof   
      
   --- 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