Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Detect if script is started from "global"?

Sep
28
2
Is it possible to detect inside a script if it was started from the command global rather than directly from the command line?
I already checked all sorts of system variables, functions etc. but could not figure out how this could be achived.

Background: I want to execute the pause command, if script is started from global, thus iterating over some directories. I do not want to pause if started from the command line without global.
 
if "global" not in %_cmdline then .....
I don't think that will work if the script is CALLed inside a GLOBAL inside another script. And _CMDLINE seems to be broken anyway!

Code:
v:\> type cmdline.btm
echo _CMDLINE = %_CMDLINE

v:\> cmdline.btm
_CMDLINE = cmdl
 
%_cmdline was my 1. attempt. Does not work at all within a script...
%cmdline does not contain the word global
%cmdline2 sends tcc into nirvana...
 
That seems to work :-)

Code:
@echo off
function runsFromGlobal=`%@if[%@regexindex[global[ /],%@execstr[history/ll/t1]] != -1,1,0]`
echo %@if[%@runsFromGlobal[] == 1,,not ]from global

runsFromGlobal could be defined in tcstart.btm.
 
Last edited:
It may not be an issue but won't that fail if the GLOBAL was in another script? Instead of looking for "global" you could look for the name of your script but that would also fail if the script was CALLed from another script.
 
I would suggest adding an option to the script itself, to tell it to pause if desired.
 
It may not be an issue but won't that fail if the GLOBAL was in another script? Instead of looking for "global" you could look for the name of your script but that would also fail if the script was CALLed from another script.
Well, it's not an issue for me. As long nobody has a better solution, this one is perfect for me.

I would suggest adding an option to the script itself, to tell it to pause if desired.
You mean as a command line parameter to the script? I don'l like that solution compared to the automatic detection of the function above.
 
Back
Top