Solved calling CMD script info

February 19, 2020 at 05:18:17
Specs: Win 10, 8GB
What I'm trying to do is this:
Suppose I have a CMD script that is run for whatever purpose, also needs to know the following:
It needs to know whether or not a a given script was called from the command prompt in the CMD-application,
or that it was called from another CMD-script (using the CALL function). In addition, it would be nice if it would know what the caller script name was.

I have an idea how to make it work, but that involves changing each of these CMD files to be adapted to contain some specific code. A better solution is that it would work from any script, no matter what code the caller script has.

Is it possible, if yes: how ?

message edited by Looge


See More: calling CMD script info

Reply ↓  Report •

#1
February 19, 2020 at 06:14:58
✔ Best Answer
maby if you where to log the CALL command from within the fuction, with the variable:
%~nx0

CALL :label-name will call the function form inside the .bat file
CALL no-colon calls the .bat / .com file in %~dp0 (the folder where the already running .bat orininates) and executes it before the "host" .bat can contuniue.

You can also pass variables from the host .bat to the 2nd bat file to call another function in the 2nd one.

But in terms of logging, im not really sure where to begin.

TL;DR yes it should be doable

i think best would be that each .bat and function also calls a function from itself echoing %~nx0 to a logg.

Could you explain some scenario's/examples?

i5-6600K[delid]@4.828GHz Core/4.627 Cache@1.456v | 4+8GB DDR4-3018MHzCL12-15-15-28-1@1.465v | Sapphire Nitro+ SE RX 590 8GB@1675Mhz core@1.180v/2236MHz


Reply ↓  Report •

#2
February 19, 2020 at 07:14:51
Yes, I have one easy example of such:

Any CMD-script that runs into some kind of error, would report such an error.
It does so ... by calling a generic script. That one is actually called error.cmd
So, take an example of "this_script.cmd", which at some points calls "error.cmd", with some parameters.

That script however - error.cmd - would have a nice feature if it could say:
"this_script.cmd" caused an error.

Keep in mind that the script "this_script.cmd" is not actually the script that is called directly.
So it's not like: I run "this_script.cmd" and it reports an error, so the error must be there.
No, there's another script, which calls different scripts, including "this_script.cmd"

Any script can error out, in this example.
How would you know it is "this_script.cmd" ?


Reply ↓  Report •

#3
February 27, 2020 at 05:47:27
Hidde, I've marked your answer as Best Answer but it doesn't comply with the requirements as posted, being the fact that I wish to avoid changes to every single script, before this feature to be working.

Reply ↓  Report •
Related Solutions


Ask Question