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,047 of 68,980    |
|    John Gray to All    |
|    Re: In second batch file, find the name     |
|    07 Sep 17 05:26:51    |
      From: jgqued@gmail.com              On Thursday, 7 September 2017 11:44:26 UTC+1, JJ wrote:       > 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              Thank you very much! It's so very obvious once you say it!              To my surprise, that environment variable is available both before and after       setlocal in the called.bat file.               ::Caller.bat        ::using environment variable        set caller=%~n0        call called.bat %parm1% %parm2% %parm3%        goto :eof               ::Called.bat        ::using environment variable        echo %%caller%% before setlocal contains %caller%        setlocal        echo %%caller%% after setlocal contains %caller%        echo Parameters are %1 %2 %3        echo Called.bat was called by %caller%        ...        endlocal        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